Author: hannes
Date: 2009-01-16 11:45:12 +0100 (Fri, 16 Jan 2009)
New Revision: 9488
Modified:
helma-ng/trunk/apps/demo/actions.js
helma-ng/trunk/modules/helma/webapp/request.js
helma-ng/trunk/src/org/helma/web/Request.java
Log:
Rewrite request HTTP method checks as properties and include more standard HTTP methods such as PUT, DELETE, and HEAD.
Make sure request.cookies contains the first cookie if there are multiple cookies with the same name.
Details at http://dev.helma.org/trac/helma/changeset/9488
Modified: helma-ng/trunk/apps/demo/actions.js
===================================================================
--- helma-ng/trunk/apps/demo/actions.js 2009-01-15 13:24:33 UTC (rev 9487)
+++ helma-ng/trunk/apps/demo/actions.js 2009-01-16 10:45:12 UTC (rev 9488)
@@ -72,7 +72,7 @@
// the local function to do the actual work
function renderPage(id) {
var previous = pages[id - 1]
- if (req.isPost() && previous) {
+ if (req.isPost && previous) {
data[previous] = req.params[previous];
}
if (id < pages.length - 1) {
Modified: helma-ng/trunk/modules/helma/webapp/request.js
===================================================================
--- helma-ng/trunk/modules/helma/webapp/request.js 2009-01-15 13:24:33 UTC (rev 9487)
+++ helma-ng/trunk/modules/helma/webapp/request.js 2009-01-16 10:45:12 UTC (rev 9488)
@@ -1,25 +1,41 @@
require('core.string');
import('helma.system', 'system');
-system.addHostObject(org.helma.web.Request);
-system.addHostObject(org.helma.web.Session);
+if (!global.Request) {
-var log = require('helma.logging').getLogger(__name__);
+ system.addHostObject(org.helma.web.Request);
+ system.addHostObject(org.helma.web.Session);
-(function() {
+ var log = require('helma.logging').getLogger(__name__);
- /**
- * Return true if this is a HTTP POST request.
- */
- this.isPost = function() {
- return this.method == "POST";
- }
+ Object.defineProperty(Request.prototype, "isGet", {
+ getter: function() {
+ return this.isMethod("GET");
+ }
+ });
- /**
- * Return true if this is a HTTP GET request.
- */
- this.isGet = function() {
- return this.method == "GET";
- }
-
-}).apply(Request.prototype);
+ Object.defineProperty(Request.prototype, "isPost", {
+ getter: function() {
+ return this.isMethod("POST");
+ }
+ });
+
+ Object.defineProperty(Request.prototype, "isPut", {
+ getter: function() {
+ return this.isMethod("PUT");
+ }
+ });
+
+ Object.defineProperty(Request.prototype, "isDelete", {
+ getter: function() {
+ return this.isMethod("DELETE");
+ }
+ });
+
+ Object.defineProperty(Request.prototype, "isHead", {
+ getter: function() {
+ return this.isMethod("HEAD");
+ }
+ });
+
+}
\ No newline at end of file
Modified: helma-ng/trunk/src/org/helma/web/Request.java
===================================================================
--- helma-ng/trunk/src/org/helma/web/Request.java 2009-01-15 13:24:33 UTC (rev 9487)
+++ helma-ng/trunk/src/org/helma/web/Request.java 2009-01-16 10:45:12 UTC (rev 9488)
@@ -102,6 +102,15 @@
}
/**
+ * Checks if the argument string matches the HTTP method of this request.
+ * @param method a method name
+ * @return true if the method matches
+ */
+ public boolean jsFunction_isMethod(String method) {
+ return method != null && method.equalsIgnoreCase(request.getMethod());
+ }
+
+ /**
* Returns any extra path information associated with the URL the client
* sent when it made this request. The extra path information follows the
* servlet path but precedes the query string. This method returns null
@@ -225,7 +234,6 @@
/**
* A JavaScript object reflecting the headers of this request.
- * @deprecated
* @return the request headers as JavaScript object
*/
public Object jsGet_headers() {
@@ -255,13 +263,19 @@
return params;
}
+ /**
+ * A JavaScript object containint the cookies the client sent with this request.
+ * @return the request cookies as JavaScript object
+ */
public Object jsGet_cookies() {
if (cookies == null) {
Cookie[] cookieArray = request.getCookies();
ParameterMap cookieMap = new ParameterMap();
if (cookieArray != null) {
for (Cookie cookie : cookieArray) {
- cookieMap.put(cookie.getName(), cookie);
+ if (!cookieMap.containsKey(cookie.getName())) {
+ cookieMap.put(cookie.getName(), cookie);
+ }
}
}
cookies = new ScriptableMap(getParentScope(), cookieMap);
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.