Skip to content

Commit

Permalink
Converts all header names to lowercase, due node automatically converts
Browse files Browse the repository at this point in the history
them

http://nodejs.org/api/http.html#http_request_headers

request.headers#
Read only map of header names and values. Header names are lower-cased.
Example:

// Prints something like:
//
// { 'user-agent': 'curl/7.22.0',
//   host: '127.0.0.1:8000',
//   accept: '*/*' }
console.log(request.headers);
  • Loading branch information
Pablo Cantero committed Oct 13, 2012
1 parent 8de8fa9 commit ac44077
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/node-static.js
Expand Up @@ -38,10 +38,10 @@ exports.Server = function (root, options) {
this.serverInfo = 'node-static/' + exports.version.join('.');
}

this.defaultHeaders['Server'] = this.serverInfo;
this.defaultHeaders['server'] = this.serverInfo;

if (this.cache !== false) {
this.defaultHeaders['Cache-Control'] = 'max-age=' + this.cache;
this.defaultHeaders['cache-control'] = 'max-age=' + this.cache;
}

for (var k in this.defaultHeaders) {
Expand Down Expand Up @@ -103,7 +103,7 @@ exports.Server.prototype.finish = function (status, headers, req, res, promise,
message: http.STATUS_CODES[status]
};

headers['Server'] = this.serverInfo;
headers['server'] = this.serverInfo;

if (!status || status >= 400) {
if (callback) {
Expand Down Expand Up @@ -194,21 +194,21 @@ exports.Server.prototype.respond = function (pathname, status, _headers, files,
// Copy default headers
for (var k in this.options.headers) { headers[k] = this.options.headers[k] }

headers['ETag'] = JSON.stringify([stat.ino, stat.size, mtime].join('-'));
headers['Date'] = new(Date)().toUTCString();
headers['Last-Modified'] = new(Date)(stat.mtime).toUTCString();
headers['etag'] = JSON.stringify([stat.ino, stat.size, mtime].join('-'));
headers['date'] = new(Date)().toUTCString();
headers['last-modified'] = new(Date)(stat.mtime).toUTCString();

// Conditional GET
// If the "If-Modified-Since" or "If-None-Match" headers
// match the conditions, send a 304 Not Modified.
if ((clientMTime || clientETag) &&
(!clientETag || clientETag === headers['ETag']) &&
(!clientETag || clientETag === headers['etag']) &&
(!clientMTime || clientMTime >= mtime)) {
finish(304, headers);
} else {
var fileExtension = path.extname(files[0]).slice(1).toLowerCase();
headers['Content-Length'] = stat.size;
headers['Content-Type'] = mime.contentTypes[fileExtension] ||
headers['content-length'] = stat.size;
headers['content-type'] = mime.contentTypes[fileExtension] ||
'application/octet-stream';

for (var k in _headers) { headers[k] = _headers[k] }
Expand Down

0 comments on commit ac44077

Please sign in to comment.