[Pkg-javascript-commits] [node-static] 108/151: Cleaned up exports in main file. Corrected package version number. Added decodeURI test back in.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:18:02 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository node-static.
commit a2a3371e15ccb1a865daed8df1253de1e096ae5c
Author: David Sargeant <david at dsargeant.com>
Date: Mon Apr 1 12:05:21 2013 -0400
Cleaned up exports in main file. Corrected package version number. Added decodeURI test back in.
---
lib/node-static.js | 62 +++++++++++++++++++++++-------------
package.json | 2 +-
test/integration/node-static-test.js | 30 +++++++++--------
3 files changed, 57 insertions(+), 37 deletions(-)
diff --git a/lib/node-static.js b/lib/node-static.js
index 267395f..098d87f 100644
--- a/lib/node-static.js
+++ b/lib/node-static.js
@@ -4,16 +4,15 @@ var fs = require('fs')
, http = require('http')
, url = require('url')
, path = require('path')
- , mime = require('mime');
+ , mime = require('mime')
+ , util = require('./node-static/util');
-exports.version = [0, 6, 7];
-
-var util = require('./node-static/util');
+// Current version
+var version = [0, 6, 7];
// In-memory file store
-exports.store = {};
-exports.indexStore = {};
-exports.mime = mime;
+var store = {};
+var indexStore = {};
Server = function (root, options) {
if (root && (typeof(root) === 'object')) { options = root; root = null }
@@ -36,7 +35,7 @@ Server = function (root, options) {
if ('serverInfo' in this.options) {
this.serverInfo = this.options.serverInfo.toString();
} else {
- this.serverInfo = 'node-static/' + exports.version.join('.');
+ this.serverInfo = 'node-static/' + version.join('.');
}
this.defaultHeaders['server'] = this.serverInfo;
@@ -59,14 +58,14 @@ Server.prototype.serveDir = function (pathname, req, res, finish) {
if (!e) {
that.respond(null, 200, {}, [htmlIndex], stat, req, res, finish);
} else {
- if (pathname in exports.indexStore) {
- streamFiles(exports.indexStore[pathname].files);
+ if (pathname in indexStore) {
+ streamFiles(indexStore[pathname].files);
} else {
// Stream a directory of files as a single file.
fs.readFile(path.join(pathname, 'index.json'), function (e, contents) {
if (e) { return finish(404, {}) }
var index = JSON.parse(contents);
- exports.indexStore[pathname] = index;
+ indexStore[pathname] = index;
streamFiles(index.files);
});
}
@@ -168,14 +167,22 @@ Server.prototype.resolve = function (pathname) {
};
Server.prototype.serve = function (req, res, callback) {
- var that = this,
- promise = new(events.EventEmitter);
+ var that = this,
+ promise = new(events.EventEmitter),
+ pathname;
- var pathname = decodeURI(url.parse(req.url).pathname);
-
var finish = function (status, headers) {
that.finish(status, headers, req, res, promise, callback);
};
+
+ try {
+ pathname = decodeURI(url.parse(req.url).pathname);
+ }
+ catch(e) {
+ return process.nextTick(function() {
+ return finish(400, {});
+ });
+ }
process.nextTick(function () {
that.servePath(pathname, 200, {}, req, res, finish).on('success', function (result) {
@@ -188,9 +195,9 @@ Server.prototype.serve = function (req, res, callback) {
};
Server.prototype.respond = function (pathname, status, _headers, files, stat, req, res, finish) {
- var mtime = Date.parse(stat.mtime),
- key = pathname || files[0],
- headers = {},
+ var mtime = Date.parse(stat.mtime),
+ key = pathname || files[0],
+ headers = {},
clientETag = req.headers['if-none-match'],
clientMTime = Date.parse(req.headers['if-modified-since']);
@@ -224,14 +231,14 @@ Server.prototype.respond = function (pathname, status, _headers, files, stat, re
// If the file was cached and it's not older
// than what's on disk, serve the cached version.
- if (this.cache && (key in exports.store) &&
- exports.store[key].stat.mtime >= stat.mtime) {
- res.end(exports.store[key].buffer);
+ if (this.cache && (key in store) &&
+ store[key].stat.mtime >= stat.mtime) {
+ res.end(store[key].buffer);
finish(status, headers);
} else {
this.stream(pathname, files, new(buffer.Buffer)(stat.size), res, function (e, buffer) {
if (e) { return finish(500, {}) }
- exports.store[key] = {
+ store[key] = {
stat: stat,
buffer: buffer,
timestamp: Date.now()
@@ -269,4 +276,13 @@ Server.prototype.stream = function (pathname, files, buffer, res, callback) {
})(files.slice(0), 0);
};
-exports.Server = Server;
+// Exports
+exports.Server = Server;
+exports.version = version;
+exports.mime = mime;
+exports.store = store;
+exports.indexStore = indexStore;
+
+
+
+
diff --git a/package.json b/package.json
index e7b6616..5a92e26 100644
--- a/package.json
+++ b/package.json
@@ -31,7 +31,7 @@
"request": "latest",
"vows": "latest"
},
- "version" : "0.6.5",
+ "version" : "0.6.7",
"engines" : { "node": ">= 0.4.1" }
}
diff --git a/test/integration/node-static-test.js b/test/integration/node-static-test.js
index 5cfacf1..0387e67 100644
--- a/test/integration/node-static-test.js
+++ b/test/integration/node-static-test.js
@@ -7,10 +7,22 @@ var fileServer = new(static.Server)(__dirname + '/../fixtures', {serverInfo: 'cu
var suite = vows.describe('node-static');
-var TEST_PORT = 8080;
+var TEST_PORT = 8080;
var TEST_SERVER = 'http://localhost:' + TEST_PORT;
var server;
var callback;
+var version = static.version.join('.');
+
+headers = {
+ 'requesting headers': {
+ topic : function(){
+ request.head(TEST_SERVER + '/index.html', this.callback);
+ }
+ }
+}
+headers['requesting headers']['should respond with node-static/' + version] = function(error, response, body){
+ assert.equal(response.headers['server'], 'node-static/' + version);
+}
suite.addBatch({
'once an http server is listening with a callback': {
@@ -75,7 +87,7 @@ suite.addBatch({
}
}
})
-/*.addBatch({
+.addBatch({
'requesting a malformed URI': {
topic: function(){
request.get(TEST_SERVER + '/a%AFc', this.callback);
@@ -85,7 +97,6 @@ suite.addBatch({
}
}
})
-*/
.addBatch({
'serving hello.txt': {
topic : function(){
@@ -176,16 +187,9 @@ suite.addBatch({
assert.isUndefined(body);
}
}
-}).addBatch({
- 'requesting headers': {
- topic : function(){
- request.head(TEST_SERVER + '/index.html', this.callback);
- },
- 'should respond with node-static/0.6.7' : function(error, response, body){
- assert.equal(response.headers['server'], 'node-static/0.6.7');
- }
- }
-}).addBatch({
+})
+.addBatch(headers)
+.addBatch({
'addings custom mime types': {
topic : function(){
static.mime.define({'application/font-woff': ['woff']});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-static.git
More information about the Pkg-javascript-commits
mailing list