You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by rb...@apache.org on 2012/10/11 14:16:44 UTC

svn commit: r1397011 - in /shindig/trunk: config/ features/src/main/javascript/features/core.io/ features/src/test/javascript/features/core.io/ java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/

Author: rbaxter85
Date: Thu Oct 11 12:16:43 2012
New Revision: 1397011

URL: http://svn.apache.org/viewvc?rev=1397011&view=rev
Log:
SHINDIG-1875
Committed For Erik Bi
File downloaded via Proxy always has name p.txt - Include file name on proxy URL because IE8 does not respect Content-Disposition

Modified:
    shindig/trunk/config/container.js
    shindig/trunk/features/src/main/javascript/features/core.io/feature.xml
    shindig/trunk/features/src/main/javascript/features/core.io/io.js
    shindig/trunk/features/src/test/javascript/features/core.io/iotest.js
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java

Modified: shindig/trunk/config/container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/config/container.js?rev=1397011&r1=1397010&r2=1397011&view=diff
==============================================================================
--- shindig/trunk/config/container.js (original)
+++ shindig/trunk/config/container.js Thu Oct 11 12:16:43 2012
@@ -156,7 +156,7 @@
   "core.io" : {
     // Note: ${Cur['gadgets.uri.proxy.path']} is an open proxy. Be careful how you expose this!
     // Note: These urls should be protocol relative (start with //)
-    "proxyUrl" : "//${Cur['default.domain.unlocked.client']}${Cur['gadgets.uri.proxy.path']}?container=%container%&refresh=%refresh%&url=%url%%authz%%rewriteMime%",
+    "proxyUrl" : "//${Cur['default.domain.unlocked.client']}${Cur['gadgets.uri.proxy.path']}%filename%?container=%container%&refresh=%refresh%&url=%url%%authz%%rewriteMime%",
     "jsonProxyUrl" : "//${Cur['default.domain.locked.client']}${CONTEXT_ROOT}/gadgets/makeRequest",
     // Note: this setting MUST be supplied in every container config object, as there is no default if it is not supplied.
     "unparseableCruft" : "throw 1; < don't be evil' >",

Modified: shindig/trunk/features/src/main/javascript/features/core.io/feature.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.io/feature.xml?rev=1397011&r1=1397010&r2=1397011&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.io/feature.xml (original)
+++ shindig/trunk/features/src/main/javascript/features/core.io/feature.xml Thu Oct 11 12:16:43 2012
@@ -35,6 +35,7 @@
   <dependency>core.json</dependency>
   <dependency>core.util.base</dependency>
   <dependency>core.util.urlparams</dependency>
+  <dependency>shindig.uri</dependency>
   <all>
     <script src="io.js"/>
     <script src="taming.js" caja="1"/>

Modified: shindig/trunk/features/src/main/javascript/features/core.io/io.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.io/io.js?rev=1397011&r1=1397010&r2=1397011&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/core.io/io.js (original)
+++ shindig/trunk/features/src/main/javascript/features/core.io/io.js Thu Oct 11 12:16:43 2012
@@ -596,9 +596,19 @@ gadgets.io = function() {
           authParam = '&authz=' + authz.toLowerCase();
         }
       }
+
+      var uri = shindig.uri(url);
+      var path = uri.getPath();
+      var fileName = "";
+      var lSlash = path.lastIndexOf('/');
+      if (lSlash !== -1) {
+        fileName = path.substring(lSlash); // include the slash
+      }
+
       var ret = proxyUrl.replace('%url%', encodeURIComponent(url)).
           replace('%host%', document.location.host).
           replace('%rawurl%', url).
+          replace('%filename%', fileName).
           replace('%refresh%', encodeURIComponent(refresh)).
           replace('%gadget%', encodeURIComponent(urlParams['url'])).
           replace('%container%', encodeURIComponent(urlParams['container'] || urlParams['synd'] || 'default')).

Modified: shindig/trunk/features/src/test/javascript/features/core.io/iotest.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/core.io/iotest.js?rev=1397011&r1=1397010&r2=1397011&view=diff
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/core.io/iotest.js (original)
+++ shindig/trunk/features/src/test/javascript/features/core.io/iotest.js Thu Oct 11 12:16:43 2012
@@ -53,6 +53,14 @@ IoTest.prototype.setSchemaless = functio
   gadgets.io.preloaded_ = [];
 };
 
+IoTest.prototype.setWithFileName = function() {
+  gadgets.config.init({ "core.io" : {
+      "proxyUrl" : "http://example.com/proxy%filename%?url=%url%&refresh=%refresh%&g=%gadget%&c=%container%",
+      "jsonProxyUrl" : "http://example.com/json",
+      "unparseableCruft" : "throw 1; < don't be evil' >"}});
+  gadgets.io.preloaded_ = [];
+};
+
 IoTest.prototype.setOAuthSupportEnabled = function() {
   gadgets.config.init({ "core.io" : {
       "proxyUrl" : "http://example.com/proxy?url=%url%&refresh=%refresh%&g=%gadget%&c=%container%%authz%",
@@ -121,6 +129,17 @@ IoTest.prototype.testGetProxyUrl_schemal
       proxied);
 };
 
+IoTest.prototype.testGetProxyUrl_withFileName = function() {
+  this.setWithFileName();
+  var proxied = gadgets.io.getProxyUrl("http://target.example.com/image.gif");
+  this.assertEquals(
+      "http://example.com/proxy/image.gif?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);

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java?rev=1397011&r1=1397010&r2=1397011&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java (original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/ProxyHandler.java Thu Oct 11 12:16:43 2012
@@ -164,7 +164,14 @@ public class ProxyHandler {
     // This does make some sites a higher value phishing target, but this can be mitigated by
     // additional referer checks.
     if (!isFlash(response.getHeader("Content-Type"), results.getHeader("Content-Type"))) {
-      response.setHeader("Content-Disposition", "attachment;filename=p.txt");
+      String contentDispositionValue = results.getHeader("Content-Disposition");
+      if (StringUtils.isBlank(contentDispositionValue)
+              || contentDispositionValue.indexOf("attachment;") == -1
+              || contentDispositionValue.indexOf("filename") == -1) {
+        response.setHeader("Content-Disposition", "attachment;filename=p.txt");
+      } else {
+        response.setHeader("Content-Disposition", contentDispositionValue);
+      }
     }
     if (results.getHeader("Content-Type") == null) {
       response.setHeader("Content-Type", "application/octet-stream");