Skip to content

Loading…

serverInfo option added #66

Merged
merged 1 commit into from

2 participants

@michaelwittig

It could be important for some environments to not tell the public that we are using node-static to serve static files. so I would like to set the serverInfo (Server header).

@phstc phstc commented on the diff
lib/node-static.js
@@ -33,11 +31,16 @@ this.Server = function (root, options) {
this.cache = false;
}
}
+ if ('serverInfo' in this.options) {
+ this.serverInfo = this.options.serverInfo.toString();
+ } else {
+ this.serverInfo = 'node-static/' + this.version.join('.');
@phstc Collaborator
phstc added a note

version does not belong to this anymore. you should use this.serverInfo = 'node-static/' + exports.version.join('.'); instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@phstc phstc added a commit that referenced this pull request
@phstc phstc Merging #66 788203a
@phstc phstc merged commit 67b723b into cloudhead:master
@phstc phstc referenced this pull request
Closed

Custom ServerInfo #67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 14, 2012
  1. @michaelwittig
Showing with 16 additions and 4 deletions.
  1. +9 −0 README.md
  2. +7 −4 lib/node-static.js
View
9 README.md
@@ -131,6 +131,15 @@ Passing `false` will disable the `Cache-Control` header.
> Defaults to `3600`
+
+#### `serverInfo` #
+
+Sets the `Server` header.
+
+example: `{ serverInfo: "myserver" }`
+
+> Defaults to `node-static/{version}`
+
#### `headers` #
Sets response headers.
View
11 lib/node-static.js
@@ -10,8 +10,6 @@ this.version = [0, 6, 0];
var mime = require('./node-static/mime');
var util = require('./node-static/util');
-var serverInfo = 'node-static/' + this.version.join('.');
-
// In-memory file store
this.store = {};
this.indexStore = {};
@@ -33,11 +31,16 @@ this.Server = function (root, options) {
this.cache = false;
}
}
+ if ('serverInfo' in this.options) {
+ this.serverInfo = this.options.serverInfo.toString();
+ } else {
+ this.serverInfo = 'node-static/' + this.version.join('.');
@phstc Collaborator
phstc added a note

version does not belong to this anymore. you should use this.serverInfo = 'node-static/' + exports.version.join('.'); instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
if (this.cache !== false) {
this.defaultHeaders['Cache-Control'] = 'max-age=' + this.cache;
}
- this.defaultHeaders['Server'] = serverInfo;
+ this.defaultHeaders['Server'] = this.serverInfo;
for (var k in this.defaultHeaders) {
this.options.headers[k] = this.options.headers[k] ||
@@ -95,7 +98,7 @@ this.Server.prototype.finish = function (status, headers, req, res, promise, cal
message: http.STATUS_CODES[status]
};
- headers['Server'] = serverInfo;
+ headers['Server'] = this.serverInfo;
if (!status || status >= 400) {
if (callback) {
Something went wrong with that request. Please try again.