Permalink
Browse files

avoid allocating the unsafe headers array with every call to isSafeHe…

…ader, and use 4 space indents
  • Loading branch information...
1 parent 97cb483 commit 24c2e8010333b118af761937f8f67d28b1874697 Nicolas LaCasse committed Feb 1, 2012
Showing with 27 additions and 29 deletions.
  1. +27 −29 lib/request.js
View
@@ -60,34 +60,32 @@ Request.prototype.end = function (s) {
this.xhr.send(this.body);
};
-Request.prototype.isSafeRequestHeader = function (headerName) {
- if (!headerName) return false;
- headerName = headerName.toLowerCase();
-
- // Taken from http://dxr.mozilla.org/mozilla/mozilla-central/content/base/src/nsXMLHttpRequest.cpp.html
- var unsafeHeaders = [
- "accept-charset",
- "accept-encoding",
- "access-control-request-headers",
- "access-control-request-method",
- "connection",
- "content-length",
- "cookie",
- "cookie2",
- "content-transfer-encoding",
- "date",
- "expect",
- "host",
- "keep-alive",
- "origin",
- "referer",
- "te",
- "trailer",
- "transfer-encoding",
- "upgrade",
- "user-agent",
- "via"
- ];
+// Taken from http://dxr.mozilla.org/mozilla/mozilla-central/content/base/src/nsXMLHttpRequest.cpp.html
+Request.unsafeHeaders = [
+ "accept-charset",
+ "accept-encoding",
+ "access-control-request-headers",
+ "access-control-request-method",
+ "connection",
+ "content-length",
+ "cookie",
+ "cookie2",
+ "content-transfer-encoding",
+ "date",
+ "expect",
+ "host",
+ "keep-alive",
+ "origin",
+ "referer",
+ "te",
+ "trailer",
+ "transfer-encoding",
+ "upgrade",
+ "user-agent",
+ "via"
+];
- return (unsafeHeaders.indexOf(headerName) === -1)
+Request.prototype.isSafeRequestHeader = function (headerName) {
+ if (!headerName) return false;
+ return (Request.unsafeHeaders.indexOf(headerName.toLowerCase()) === -1)
};

0 comments on commit 24c2e80

Please sign in to comment.