summaryrefslogtreecommitdiffstats
path: root/net/data/proxy_resolver_v8_unittest/passthrough.js
diff options
context:
space:
mode:
Diffstat (limited to 'net/data/proxy_resolver_v8_unittest/passthrough.js')
-rw-r--r--net/data/proxy_resolver_v8_unittest/passthrough.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/net/data/proxy_resolver_v8_unittest/passthrough.js b/net/data/proxy_resolver_v8_unittest/passthrough.js
new file mode 100644
index 0000000..832ac66
--- /dev/null
+++ b/net/data/proxy_resolver_v8_unittest/passthrough.js
@@ -0,0 +1,45 @@
+// Return a single-proxy result, which encodes ALL the arguments that were
+// passed to FindProxyForURL().
+
+function FindProxyForURL(url, host) {
+ if (arguments.length != 2) {
+ throw "Wrong number of arguments passed to FindProxyForURL!";
+ return "FAIL";
+ }
+
+ return "PROXY " + makePseudoHost(url + "." + host);
+}
+
+// Form a string that kind-of resembles a host. We will replace any
+// non-alphanumeric character with a dot, then fix up the oddly placed dots.
+function makePseudoHost(str) {
+ var result = "";
+
+ for (var i = 0; i < str.length; ++i) {
+ var c = str.charAt(i);
+ if (!isValidPseudoHostChar(c)) {
+ c = '.'; // Replace unsupported characters with a dot.
+ }
+
+ // Take care not to place multiple adjacent dots,
+ // a dot at the beginning, or a dot at the end.
+ if (c == '.' &&
+ (result.length == 0 ||
+ i == str.length - 1 ||
+ result.charAt(result.length - 1) == '.')) {
+ continue;
+ }
+ result += c;
+ }
+ return result;
+}
+
+function isValidPseudoHostChar(c) {
+ if (c >= '0' && c <= '9')
+ return true;
+ if (c >= 'a' && c <= 'z')
+ return true;
+ if (c >= 'A' && c <= 'Z')
+ return true;
+ return false;
+}