Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,33 @@ var fs = require('fs'),
auth = require('basic-auth'),
httpProxy = require('http-proxy'),
corser = require('corser'),
path = require('path'),
secureCompare = require('secure-compare');

// a hacky and direct workaround to fix https://github.com/http-party/http-server/issues/525
function getCaller() {
try {
var stack = new Error().stack;
var stackLines = stack.split('\n');
var callerStack = stackLines[3];
return callerStack.match(/at (.+) \(/)[1];
}
catch (error) {
return '';
}
}

var _pathNormalize = path.normalize;
path.normalize = function (p) {
var caller = getCaller();
var result = _pathNormalize(p);
// https://github.com/jfhbrook/node-ecstatic/blob/master/lib/ecstatic.js#L20
if (caller === 'decodePathname') {
result = result.replace(/\\/g, '/');
}
return result;
};

//
// Remark: backwards compatibility for previous
// case convention of HTTP
Expand Down