r9762 - in helma-ng/trunk: apps/demo modules/helma modules/helma/webapp
[email protected] Thu, 14 May 2009 17:27:46 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090514152746.721EB3D0D6@mia> |
Author: hannes
Date: 2009-05-14 17:27:46 +0200 (Thu, 14 May 2009)
New Revision: 9762
Modified:
helma-ng/trunk/apps/demo/config.js
helma-ng/trunk/modules/helma/webapp.js
helma-ng/trunk/modules/helma/webapp/request.js
Log:
Implement redirection to URIs with trailing slash for requests that resolve to the default action.
Details at http://dev.helma.org/trac/helma/changeset/9762
Modified: helma-ng/trunk/apps/demo/config.js
===================================================================
--- helma-ng/trunk/apps/demo/config.js 2009-05-14 15:27:40 UTC (rev 9761)
+++ helma-ng/trunk/apps/demo/config.js 2009-05-14 15:27:46 UTC (rev 9762)
@@ -4,7 +4,7 @@
exports.urls = [
[ '/mount/point', 'webmodule' ],
- [ '/storage/', 'storage/config' ],
+ [ '/storage', 'storage/config' ],
[ '/', 'actions' ],
];
Modified: helma-ng/trunk/modules/helma/webapp/request.js
===================================================================
--- helma-ng/trunk/modules/helma/webapp/request.js 2009-05-14 15:27:40 UTC (rev 9761)
+++ helma-ng/trunk/modules/helma/webapp/request.js 2009-05-14 15:27:46 UTC (rev 9762)
@@ -17,6 +17,7 @@
define("charset", readWritePropertyDesc(servletRequest, "characterEncoding"));
define("port", readOnlyPropertyDesc(servletRequest, "port"));
define("path", readOnlyPropertyDesc(servletRequest, "requestURI"));
+ define("queryString", readOnlyPropertyDesc(servletRequest, "queryString"));
define("method", readOnlyPropertyDesc(servletRequest, "method"));
define("pathDecoded", {
@@ -84,6 +85,18 @@
return headers;
}
});
+
+ define("checkTrailingSlash", {
+ value: function checkTrailingSlash() {
+ // only redirect for GET requests
+ print(this.path, this.isGet);
+ if (!this.path.endsWith("/") && this.isGet) {
+ var path = this.queryString ?
+ this.path + "/?" + this.queryString : this.path + "/";
+ throw {redirect: path};
+ }
+ }
+ });
}
function Session(servletRequest) {
Modified: helma-ng/trunk/modules/helma/webapp.js
===================================================================
--- helma-ng/trunk/modules/helma/webapp.js 2009-05-14 15:27:40 UTC (rev 9761)
+++ helma-ng/trunk/modules/helma/webapp.js 2009-05-14 15:27:46 UTC (rev 9762)
@@ -90,13 +90,15 @@
if (log.isDebugEnabled) log.debug("module: " + module);
// cut matching prefix from path
path = path.substring(match[0].length);
- // remove leading and trailing slashes
- path = path.replace(/^\/+|\/+$/g, "");
- //split
- var pathArray = path.split(/\/+/);
+ //remove leading and trailing slashes and split
+ var pathArray = path.replace(/^\/+|\/+$/g, "").split(/\/+/);
var action = getAction(module, pathArray[0]);
// log.debug("got action: " + action);
if (typeof action == "function" && pathArray.length <= action.length) {
+ // default action - make sure request path has trailing slash
+ if (!pathArray[0]) {
+ req.checkTrailingSlash()
+ }
// set req.actionPath to the part of the path that resolves to the action
actionPath.push(match[0], pathArray[0] || "index");
req.actionPath = actionPath.join("/").replace(/\/+/g, "/");
@@ -116,9 +118,12 @@
}
return req.process();
} else if (module.urls instanceof Array) {
- // nested app
+ // nested app - make sure request path has trailing slash
+ if (!path) {
+ req.checkTrailingSlash();
+ }
actionPath.push(match[0]);
- return resolveInConfig(module, path, match[0]);
+ return resolveInConfig(module, path, match[0] + "/");
} else {
break;
}