Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pass the request downstream

When the directory does not exist, the directory middleware should
pass the request downstream.
  • Loading branch information...
commit 4494d1f4889580453cbb98c22766fba8d3153ddd 1 parent 7ef49d1
@mjackson authored
Showing with 45 additions and 0 deletions.
  1. +5 −0 CHANGES
  2. +2 −0  lib/directory.js
  3. +38 −0 test/directory_test.js
View
5 CHANGES
@@ -1,3 +1,8 @@
+= HEAD
+
+ * Fixed a bug where the request would not return properly when using the
+ directory middleware and the directory is not found.
+
= 0.12.3 / 2012-03-23
* Ignore broken symlinks when displaying a directory listing using
View
2  lib/directory.js
@@ -45,6 +45,8 @@ module.exports = function (app, root) {
app(env, callback);
}
});
+ } else {
+ app(env, callback);
}
});
}
View
38 test/directory_test.js
@@ -0,0 +1,38 @@
+var path = require("path"),
+ assert = require("assert"),
+ vows = require("vows"),
+ mock = require("./../lib/mock"),
+ utils = require("./../lib/utils"),
+ directory = require("./../lib/directory");
+
+vows.describe("directory").addBatch({
+ "A directory middleware": {
+ "when the request targets a directory that is present": {
+ topic: function () {
+ var app = directory(utils.notFound, __dirname);
+ mock.request("/_files", app, this.callback);
+ },
+ "should return a directory listing of that directory": function (err, status, headers, body) {
+ assert.equal(status, 200);
+ }
+ },
+ "when the request targets a directory that is not present": {
+ topic: function () {
+ var app = directory(utils.notFound, __dirname);
+ mock.request("/non-existant", app, this.callback);
+ },
+ "should pass the request downstream": function (err, status, headers, body) {
+ assert.equal(status, 404);
+ }
+ },
+ "when the request targets a file that is present": {
+ topic: function () {
+ var app = directory(utils.notFound, __dirname);
+ mock.request("/" + path.basename(__filename), app, this.callback);
+ },
+ "should pass the request downstream": function (err, status, headers, body) {
+ assert.equal(status, 404);
+ }
+ }
+ }
+}).export(module);

0 comments on commit 4494d1f

Please sign in to comment.
Something went wrong with that request. Please try again.