Permalink
Browse files

Bug fixes for HTTP apps

Consistent order of directory lists.

Permanent middleware exposed.
  • Loading branch information...
1 parent 9365068 commit 88eeab7fb4f6ae1c5cb843a39bb9fa79f22c637e @kriskowal committed Mar 18, 2013
Showing with 38 additions and 48 deletions.
  1. +2 −21 http-apps.js
  2. +0 −23 http-apps/cache.js
  3. +11 −0 http-apps/content.js
  4. +20 −0 http-apps/decorators.js
  5. +3 −2 http-apps/fs.js
  6. +2 −2 spec/http-apps/directory-list-spec.js
View
@@ -60,6 +60,7 @@ exports.content = ContentApps.content;
exports.ok = ContentApps.ok;
exports.ContentRequest = ContentApps.ContentRequest;
exports.Inspect = ContentApps.Inspect;
+exports.ParseQuery = ContentApps.ParseQuery;
var FsApps = require("./http-apps/fs");
exports.File = FsApps.File;
@@ -143,29 +144,9 @@ exports.Debug = DecoratorApps.Debug;
exports.Log = DecoratorApps.Log;
exports.Time = DecoratorApps.Time;
exports.Headers = DecoratorApps.Headers;
+exports.Permanent = DecoratorApps.Permanent;
exports.Decorators = DecoratorApps.Decorators;
-/**
- */
-exports.ParseQuery = function (app) {
- return function (request, response) {
- request.query = QS.parse(URL.parse(request.url).query || "");
- return app(request, response);
- };
-};
-
-// Create an application from the "app" exported by a module
-exports.require = function (id, _require) {
- _require = _require || require;
- var async = _require.async || _require;
- var exports = async(id);
- return function (request, response) {
- return Q.when(exports, function (exports) {
- return exports.app(request, response);
- });
- }
-};
-
var CookieApps = require("./http-apps/cookie");
exports.CookieJar = CookieApps.CookieJar;
View
@@ -1,23 +0,0 @@
-
-var RouteApps = require("./route");
-
-var farFuture =
- 1000 * // ms
- 60 * // s
- 60 * // m
- 24 * // h
- 365 * // d
- 10; // years
-exports.Permanent = function (app, future) {
- future = future || function () {
- return new Date(new Date().getTime() + farFuture);
- };
- app = RouteApps.Tap(app, function (request, response) {
- request.permanent = future;
- });
- app = RouteApps.Trap(app, function (response, request) {
- response.headers["expires"] = "" + future();
- });
- return app;
-};
-
View
@@ -1,5 +1,7 @@
var Negotiate = require("./negotiate");
+var QS = require("qs");
+var URL = require("url2");
/**
* Makes an app that returns a response with static content
@@ -80,3 +82,12 @@ exports.Inspect = function (app) {
}});
};
+/**
+ */
+exports.ParseQuery = function (app) {
+ return function (request, response) {
+ request.query = QS.parse(URL.parse(request.url).query || "");
+ return app(request, response);
+ };
+};
+
@@ -143,6 +143,26 @@ exports.Headers = function (app, headers) {
};
};
+var farFuture =
+ 1000 * // ms
+ 60 * // s
+ 60 * // m
+ 24 * // h
+ 365 * // d
+ 10; // years
+exports.Permanent = function (app, future) {
+ future = future || function () {
+ return new Date(new Date().getTime() + farFuture);
+ };
+ app = RouteApps.Tap(app, function (request, response) {
+ request.permanent = future;
+ });
+ app = RouteApps.Trap(app, function (response, request) {
+ response.headers["expires"] = "" + future();
+ });
+ return app;
+};
+
/**
* Wraps a Q-JSGI application in a sequence of decorators.
* @param {Array * Decorator} decorators
View
@@ -251,7 +251,7 @@ exports.listDirectoryHtmlFragment = function (request, response) {
htmlFragment: {
forEach: function (write) {
write("<ul class=\"directory-index\">\n");
- Object.keys(data).forEach(function (name) {
+ Object.keys(data).sort().forEach(function (name) {
var stat = data[name];
var suffix = "";
if (stat.type === "directory") {
@@ -276,7 +276,7 @@ exports.listDirectoryText = function (request, response) {
},
body: {
forEach: function (write) {
- Object.keys(data).forEach(function (name) {
+ Object.keys(data).sort().forEach(function (name) {
var stat = data[name];
var suffix = "";
if (stat.type === "directory") {
@@ -334,6 +334,7 @@ exports.listDirectoryData = function (request, response) {
var fs = request.fs;
return Q.invoke(fs, "list", response.directory)
.then(function (list) {
+ list.sort();
return list.map(function (name) {
return Q.invoke(fs, "stat", fs.join(response.directory, name))
.then(function (stat) {
@@ -30,7 +30,7 @@ describe("directory lists", function () {
charset: 'utf-8'
})
.then(function (content) {
- expect(content).toEqual("9012/\n1234.txt\n5678.txt\n");
+ expect(content).toEqual("1234.txt\n5678.txt\n9012/\n");
})
.finally(server.stop);
});
@@ -70,9 +70,9 @@ describe("directory lists", function () {
" </head>\n" +
" <body>\n" +
" <ul class=\"directory-index\">\n" +
- " <li class=\"entry directory\"><a href=\"9012/\">9012/</a></li>\n" +
" <li class=\"entry file\"><a href=\"1234.txt\">1234.txt</a></li>\n" +
" <li class=\"entry file\"><a href=\"5678.txt\">5678.txt</a></li>\n" +
+ " <li class=\"entry directory\"><a href=\"9012/\">9012/</a></li>\n" +
" </ul>\n" +
" </body>\n" +
"</html>\n"

0 comments on commit 88eeab7

Please sign in to comment.