diff options
author | Andrew Azores <[email protected]> | 2013-09-26 10:25:33 -0400 |
---|---|---|
committer | Andrew Azores <[email protected]> | 2013-09-26 10:25:33 -0400 |
commit | c824b24b3c7656e6230b6c1d398a927b1225f0c2 (patch) | |
tree | dc6594b350e9583b1bda9d1be35259e03f9ce9fa /netx/net | |
parent | 22c0eae35d290f25bfd69b937c09c10b6f961db7 (diff) |
Fix for PR1204, handling of query strings and absolute paths.
Absolute paths in resource URLs are correctly handled when appended to host
URLs and URL query strings are not removed.
* netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java:
(getVersionedUrlUsingQuery) renamed to getVersionedUrl, refactored
construction of URL
* plugin/icedteanp/java/sun/applet/PluginAppletViewer.java:
(requestPluginProxyInfo) extracted proxy URI logic.
(processProxyUri) new method for finding proxy URIs, handles absolute
resource paths correctly
* tests/netx/unit/net/sourceforge/jnlp/cache/ResourceUrlCreatorTest.java:
added tests for ResourceUrlCreator#getVersionedUrl
* tests/netx/unit/sun/applet/PluginAppletViewerTest.java: added tests for
PluginAppletViewer.processProxyUri
* tests/reproducers/simple/AbsolutePathsAndQueryStrings/resources/AbsolutePathsAndQueryStrings.html:
new reproducer checks that absolute paths and query strings in resource
URLs are properly handled, and caching still works
* tests/reproducers/simple/AbsolutePathsAndQueryStrings/resources/AbsolutePathsAndQueryStrings.jnlp:
same
* tests/reproducers/simple/AbsolutePathsAndQueryStrings/testcases/AbsolutePathsAndQueryStrings.java:
same
Diffstat (limited to 'netx/net')
-rw-r--r-- | netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java b/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java index 68ab009..0da5466 100644 --- a/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java +++ b/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java @@ -38,6 +38,8 @@ exception statement from your version. */ package net.sourceforge.jnlp.cache; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.LinkedList; import java.util.List; @@ -89,7 +91,7 @@ public class ResourceUrlCreator { } } - url = getVersionedUrlUsingQuery(resource); + url = getVersionedUrl(resource); urls.add(url); urls.add(resource.getLocation()); @@ -146,29 +148,29 @@ public class ResourceUrlCreator { } /** - * Returns the URL for a resource, relying on HTTP query for getting the - * right version + * Returns the URL for a resource, including the resource's version number in the query string * * @param resource the resource to get the url for */ - protected URL getVersionedUrlUsingQuery(Resource resource) { - String actualLocation = resource.getLocation().getProtocol() + "://" - + resource.getLocation().getHost(); - if (resource.getLocation().getPort() != -1) { - actualLocation += ":" + resource.getLocation().getPort(); - } - actualLocation += resource.getLocation().getPath(); - if (resource.requestVersion != null - && resource.requestVersion.isVersionId()) { - actualLocation += "?version-id=" + resource.requestVersion; - } - URL versionedURL; + protected URL getVersionedUrl(Resource resource) { + URL resourceUrl = resource.getLocation(); try { - versionedURL = new URL(actualLocation); + String query = resourceUrl.getQuery(); // returns null if there was no query string + if (resource.requestVersion != null && resource.requestVersion.isVersionId()) { + if (query == null) { + query = ""; + } else { + query += "&"; + } + query += "version-id=" + resource.requestVersion; + } + URI uri = new URI(resourceUrl.getProtocol(), resourceUrl.getUserInfo(), resourceUrl.getHost(), resourceUrl.getPort(), resourceUrl.getPath(), query, null); + return uri.toURL(); } catch (MalformedURLException e) { - return resource.getLocation(); + return resourceUrl; + } catch (URISyntaxException e) { + return resourceUrl; } - return versionedURL; } -}
\ No newline at end of file +} |