diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java index 89c1f7dbd..ccb4d18a1 100644 --- a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java +++ b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java @@ -354,13 +354,14 @@ public class URIUtils { * * @param uri the original URI * @return the URI without dot segments + * + * @since 4.5 */ - static URI normalizeSyntax(final URI uri) throws URISyntaxException { + public static URI normalizeSyntax(final URI uri) throws URISyntaxException { if (uri.isOpaque() || uri.getAuthority() == null) { // opaque and file: URIs return uri; } - Args.check(uri.isAbsolute(), "Base URI must be absolute"); final URIBuilder builder = new URIBuilder(uri); final List inputSegments = URLEncodedUtils.parsePathSegments(uri.getPath()); final Stack outputSegments = new Stack(); diff --git a/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java b/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java index 9417aaa66..fbca9293c 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java @@ -146,13 +146,14 @@ public class DefaultRedirectStrategy implements RedirectStrategy { final RequestConfig config = clientContext.getRequestConfig(); URI uri = createLocationURI(location); - if (config.isNormalizeUri()) { - uri = uri.normalize(); - } - // rfc2616 demands the location value be a complete URI - // Location = "Location" ":" absoluteURI try { + if (config.isNormalizeUri()) { + uri = URIUtils.normalizeSyntax(uri); + } + + // rfc2616 demands the location value be a complete URI + // Location = "Location" ":" absoluteURI if (!uri.isAbsolute()) { if (!config.isRelativeRedirectsAllowed()) { throw new ProtocolException("Relative redirect location '"