[Pkg-javascript-commits] [node-static] 124/151: improved fix and added test cases

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:18:03 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 6af107cad1fc28a7e14f5d5391f2c89d529b4e11
Author: TeeTeeHaa <teeteehaa at server.fake>
Date:   Tue May 28 23:13:26 2013 +0200

    improved fix and added test cases
    
    improved issue regarding missing trailing slash in URL when using
    default file "index.html" and added test cases
---
 lib/node-static.js                   |  6 ++---
 test/fixtures/there/index.html       |  8 ++++++
 test/integration/node-static-test.js | 49 ++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/lib/node-static.js b/lib/node-static.js
index 358ceef..e48263f 100644
--- a/lib/node-static.js
+++ b/lib/node-static.js
@@ -60,10 +60,10 @@ Server.prototype.serveDir = function (pathname, req, res, finish) {
             var headers = {};
             var originalPathname = decodeURI(url.parse(req.url).pathname);
             if (originalPathname.length && originalPathname.charAt(originalPathname.length - 1) !== '/') {
-                status = 301;
-                headers['Location'] = originalPathname + '/';
+                return finish(301, { 'Location': originalPathname + '/' });
+            } else {
+                that.respond(null, status, headers, [htmlIndex], stat, req, res, finish);
             }
-            that.respond(null, status, headers, [htmlIndex], stat, req, res, finish);
         } else {
             if (pathname in indexStore) {
                 streamFiles(indexStore[pathname].files);
diff --git a/test/fixtures/there/index.html b/test/fixtures/there/index.html
new file mode 100644
index 0000000..6798b09
--- /dev/null
+++ b/test/fixtures/there/index.html
@@ -0,0 +1,8 @@
+<html lang="en">
+<head>
+	<title>Other page</title>
+</head>
+<body>
+	hello there!
+</body>
+</html>
diff --git a/test/integration/node-static-test.js b/test/integration/node-static-test.js
index c0f2e84..c1e5d39 100644
--- a/test/integration/node-static-test.js
+++ b/test/integration/node-static-test.js
@@ -197,4 +197,53 @@ suite.addBatch({
       assert.equal(static.mime.lookup('woff'), 'application/font-woff');
     }
   }
+})
+.addBatch({
+  'serving subdirectory index': {
+    topic : function(){
+      request.get(TEST_SERVER + '/there/', this.callback); // with trailing slash
+    },
+    'should respond with 200' : function(error, response, body){
+      assert.equal(response.statusCode, 200);
+    },
+    'should respond with text/html': function(error, response, body){
+      assert.equal(response.headers['content-type'], 'text/html');
+    }
+  }
+})
+.addBatch({
+  'redirecting to subdirectory index': {
+    topic : function(){
+      request.get({ url: TEST_SERVER + '/there', followRedirect: false }, this.callback); // without trailing slash
+    },
+    'should respond with 301' : function(error, response, body){
+      assert.equal(response.statusCode, 301);
+    },
+    'should respond with location header': function(error, response, body){
+      assert.equal(response.headers['location'], '/there/'); // now with trailing slash
+    },
+    'should respond with empty string body' : function(error, response, body){
+      assert.equal(body, '');
+    }
+  }
+})
+.addBatch({
+  'requesting a subdirectory (with trailing slash) not found': {
+    topic : function(){
+      request.get(TEST_SERVER + '/notthere/', this.callback); // with trailing slash
+    },
+    'should respond with 404' : function(error, response, body){
+      assert.equal(response.statusCode, 404);
+    }
+  }
+})
+.addBatch({
+  'requesting a subdirectory (without trailing slash) not found': {
+    topic : function(){
+      request.get({ url: TEST_SERVER + '/notthere', followRedirect: false }, this.callback); // without trailing slash
+    },
+    'should respond with 404' : function(error, response, body){
+      assert.equal(response.statusCode, 404);
+    }
+  }
 }).export(module);

-- 
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