[Zrouter-src] ZRouter.org: push to zconf++ libzhttp/request_handler.cpp

zrouter-src at zrouter.org zrouter-src at zrouter.org
Tue Jan 31 20:44:18 UTC 2012


details:   /rev/2a89ece7f945
changeset: 58:2a89ece7f945
user:      "Nicolai Petri <nicolai at petri.dk>"
date:      Tue Jan 31 21:43:40 2012 +0100
description:
If someone requests /foo/bar/directory then do a redirect to /foo/bar/directory/ .. makes sencha samples apps work and it's good karma.

diffstat:

 libzhttp/request_handler.cpp |  9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diffs (28 lines):

diff -r 896d618e6a64 -r 2a89ece7f945 libzhttp/request_handler.cpp
--- a/libzhttp/request_handler.cpp	Tue Jan 31 21:42:44 2012 +0100
+++ b/libzhttp/request_handler.cpp	Tue Jan 31 21:43:40 2012 +0100
@@ -15,6 +15,7 @@
 #include <iostream>
 #include <boost/lexical_cast.hpp>
 #include <boost/tokenizer.hpp>
+#include <boost/filesystem.hpp>
 #include "mime_types.hpp"
 #include "reply.hpp"
 #include "request.hpp"
@@ -64,9 +65,15 @@
 				}
 				++hi;
 			}
-			// If path ends in slash (i.e. is a directory) then add "index.html".
+			// If path is a directory then add "index.html".
 			if (request_path[request_path.size() - 1] == '/') {
 				request_path += "index.html";
+			} else if (boost::filesystem::is_directory(doc_root_ + request_path)) {
+				// Gracefully add missing / by means of a redirect if we are a directory
+				rep = reply::stock_reply(reply::moved_temporarily);
+				rep.headers[0].name = "Location";
+				rep.headers[0].value = request_path + "/";
+				return;
 			}
 
 			// Determine the file extension.


More information about the Zrouter-src mailing list