HTTPCLIENT-755: Workaround for known bugs in java.net.URI.resolve() (Bug ID: 4708535)
Contributed by Johannes Koch <johannes.koch at fit.fraunhofer.de> git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@632273 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a24d0b2de1
commit
2588e16238
|
@ -1,3 +1,10 @@
|
|||
Changes since 4.0 Alpha 3
|
||||
-------------------
|
||||
|
||||
* [HTTPCLIENT-755] Workaround for known bugs in java.net.URI.resolve()
|
||||
Bug ID: 4708535
|
||||
Contributed by Johannes Koch <johannes.koch at fit.fraunhofer.de>
|
||||
|
||||
Release 4.0 Alpha 3
|
||||
-------------------
|
||||
|
||||
|
|
|
@ -194,6 +194,46 @@ public class URLUtils {
|
|||
return rewriteURI(uri, target, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a URI reference against a base URI. Work-around for bug in
|
||||
* java.net.URI (<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>)
|
||||
*
|
||||
* @param baseURI the base URI
|
||||
* @param reference the URI reference
|
||||
* @return the resulting URI
|
||||
*/
|
||||
public static URI resolve(final URI baseURI, final String reference) {
|
||||
return URLUtils.resolve(baseURI, URI.create(reference));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a URI reference against a base URI. Work-around for bug in
|
||||
* java.net.URI (<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>)
|
||||
*
|
||||
* @param baseURI the base URI
|
||||
* @param reference the URI reference
|
||||
* @return the resulting URI
|
||||
*/
|
||||
public static URI resolve(final URI baseURI, URI reference){
|
||||
if (baseURI == null) {
|
||||
throw new IllegalArgumentException("Base URI may nor be null");
|
||||
}
|
||||
if (reference == null) {
|
||||
throw new IllegalArgumentException("Reference URI may nor be null");
|
||||
}
|
||||
boolean emptyReference = reference.toString().length() == 0;
|
||||
if (emptyReference) {
|
||||
reference = URI.create("#");
|
||||
}
|
||||
URI resolved = baseURI.resolve(reference);
|
||||
if (emptyReference) {
|
||||
String resolvedString = resolved.toString();
|
||||
resolved = URI.create(resolvedString.substring(0,
|
||||
resolvedString.indexOf('#')));
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class should not be instantiated.
|
||||
*/
|
||||
|
|
|
@ -138,7 +138,7 @@ public class DefaultRedirectHandler implements RedirectHandler {
|
|||
try {
|
||||
URI requestURI = new URI(request.getRequestLine().getUri());
|
||||
URI absoluteRequestURI = URLUtils.rewriteURI(requestURI, target, true);
|
||||
uri = absoluteRequestURI.resolve(uri);
|
||||
uri = URLUtils.resolve(absoluteRequestURI, uri);
|
||||
} catch (URISyntaxException ex) {
|
||||
throw new ProtocolException(ex.getMessage(), ex);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue