[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [meek/master] Factor out requestOk.



commit ef76dd14d419cdb79542f57dbdcae7a2914fd3e8
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Sun Feb 22 20:12:23 2015 -0800

    Factor out requestOk.
---
 firefox/components/main.js |   52 ++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/firefox/components/main.js b/firefox/components/main.js
index 6df4950..ea5d050 100644
--- a/firefox/components/main.js
+++ b/firefox/components/main.js
@@ -143,6 +143,31 @@ MeekHTTPHelper.lookupStatus = function(status) {
     return null;
 };
 
+// Enforce restrictions on what requests we are willing to make. These can
+// probably be loosened up. Try and rule out anything unexpected until we
+// know we need otherwise.
+MeekHTTPHelper.requestOk = function(req) {
+    if (req.method === undefined) {
+        dump("req missing \"method\".\n");
+        return false;
+    }
+    if (req.url === undefined) {
+        dump("req missing \"url\".\n");
+        return false;
+    }
+
+    if (req.method !== "POST") {
+        dump("req.method is " + JSON.stringify(req.method) + ", not \"POST\".\n");
+        return false;
+    }
+    if (!(req.url.startsWith("http://";) || req.url.startsWith("https://";))) {
+        dump("req.url doesn't start with \"http://\"; or \"https://\".\n";);
+        return false;
+    }
+
+    return true;
+};
+
 // Return an nsIProxyInfo according to the given specification. Returns null on
 // error.
 // https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIProxyInfo
@@ -222,7 +247,7 @@ MeekHTTPHelper.LocalConnectionHandler.prototype = {
 
     makeRequest: function(req) {
         // dump("makeRequest " + JSON.stringify(req) + "\n");
-        if (!this.requestOk(req)) {
+        if (!MeekHTTPHelper.requestOk(req)) {
             MeekHTTPHelper.sendResponse(this.transport, {"error": "request failed validation"});
             return;
         }
@@ -273,31 +298,6 @@ MeekHTTPHelper.LocalConnectionHandler.prototype = {
         }.bind(this));
         this.channel.asyncOpen(this.listener, this.channel);
     },
-
-    // Enforce restrictions on what requests we are willing to make. These can
-    // probably be loosened up. Try and rule out anything unexpected until we
-    // know we need otherwise.
-    requestOk: function(req) {
-        if (req.method === undefined) {
-            dump("req missing \"method\".\n");
-            return false;
-        }
-        if (req.url === undefined) {
-            dump("req missing \"url\".\n");
-            return false;
-        }
-
-        if (req.method !== "POST") {
-            dump("req.method is " + JSON.stringify(req.method) + ", not \"POST\".\n");
-            return false;
-        }
-        if (!(req.url.startsWith("http://";) || req.url.startsWith("https://";))) {
-            dump("req.url doesn't start with \"http://\"; or \"https://\".\n";);
-            return false;
-        }
-
-        return true;
-    },
 };
 
 // RequestReader reads a JSON-encoded request from the given transport, and

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits