You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by jo...@gmail.com on 2010/03/23 23:35:52 UTC

Support schemaless URLs in gadgets.io.getProxyUrl (issue705041)

Reviewers: shindig.remailer_gmail.com,

Description:
Schemaless URLs seem to work fine except in the SWF + AS3
ExternalInterface case, where despite actually resolving to the same
protocol+host, authority-mismatch errors occur. Given JS has access to
the current protocol anyway, we can simply use it to avoid this case.
This is similar to the way makeRequest works.

Please review this at http://codereview.appspot.com/705041/show

Affected files:
   features/src/main/javascript/features/core.io/io.js
   features/src/test/javascript/features/core.io/iotest.js


Index: features/src/test/javascript/features/core.io/iotest.js
===================================================================
--- features/src/test/javascript/features/core.io/iotest.js	(revision  
922057)
+++ features/src/test/javascript/features/core.io/iotest.js	(working copy)
@@ -42,6 +42,13 @@
    gadgets.io.preloaded_ = [];
  };

+IoTest.prototype.setSchemaless = function() {
+  gadgets.config.init({ "core.io" : {
+      "proxyUrl" : "//example.com/proxy?url=%url%&refresh=%refresh%&g=%gadget%&c=%container%",
+      "jsonProxyUrl" : "http://example.com/json" }});
+  gadgets.io.preloaded_ = [];
+};
+
  IoTest.prototype.tearDown = function() {
    gadgets.util.getUrlParameters = this.oldGetUrlParameters;
    window.XMLHttpRequest = this.oldXMLHTTPRequest;
@@ -79,6 +86,18 @@
        proxied);
  };

+IoTest.prototype.testGetProxyUrl_schemaless = function() {
+  this.setSchemaless();
+  window.location = { protocol: "https:" };
+  var proxied =  
gadgets.io.getProxyUrl("http://target.example.com/image.gif");
+  this.assertEquals(
+      "https://example.com/proxy?url=http%3a%2f%2ftarget.example.com%2fimage.gif"  
+
+          "&refresh=3600" +
+          "&g=http%3a%2f%2fwww.gadget.com%2fgadget.xml" +
+          "&c=foo",
+      proxied);
+};
+
  IoTest.prototype.testEncodeValues = function() {
    var x = gadgets.io.encodeValues({ 'foo' : 'bar' });
    this.assertEquals("foo=bar", x);
Index: features/src/main/javascript/features/core.io/io.js
===================================================================
--- features/src/main/javascript/features/core.io/io.js	(revision 922057)
+++ features/src/main/javascript/features/core.io/io.js	(working copy)
@@ -497,13 +497,17 @@

        var rewriteMimeParam =
            params.rewriteMime ? "&rewriteMime=" +  
encodeURIComponent(params.rewriteMime) : "";
-      return config.proxyUrl.replace("%url%", encodeURIComponent(url)).
+      var ret = config.proxyUrl.replace("%url%", encodeURIComponent(url)).
            replace("%host%", document.location.host).
            replace("%rawurl%", url).
            replace("%refresh%", encodeURIComponent(refresh)).
            replace("%gadget%", encodeURIComponent(urlParams.url)).
            replace("%container%", encodeURIComponent(urlParams.container ||  
urlParams.synd)).
            replace("%rewriteMime%", rewriteMimeParam);
+      if (ret.indexOf('//') == 0) {
+        ret = window.location.protocol + ret;
+      }
+      return ret;
      }
    };
  }();