DefaultRedirectStrategy to use URIUtils#normalizeSyntax method to normalize redirect location URI

This commit is contained in:
Oleg Kalnichevski 2019-02-16 01:35:45 +01:00
parent 4a463ebf4e
commit be77dc917f
2 changed files with 9 additions and 7 deletions

View File

@ -354,13 +354,14 @@ public class URIUtils {
* *
* @param uri the original URI * @param uri the original URI
* @return the URI without dot segments * @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) { if (uri.isOpaque() || uri.getAuthority() == null) {
// opaque and file: URIs // opaque and file: URIs
return uri; return uri;
} }
Args.check(uri.isAbsolute(), "Base URI must be absolute");
final URIBuilder builder = new URIBuilder(uri); final URIBuilder builder = new URIBuilder(uri);
final List<String> inputSegments = URLEncodedUtils.parsePathSegments(uri.getPath()); final List<String> inputSegments = URLEncodedUtils.parsePathSegments(uri.getPath());
final Stack<String> outputSegments = new Stack<String>(); final Stack<String> outputSegments = new Stack<String>();

View File

@ -146,13 +146,14 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
final RequestConfig config = clientContext.getRequestConfig(); final RequestConfig config = clientContext.getRequestConfig();
URI uri = createLocationURI(location); URI uri = createLocationURI(location);
if (config.isNormalizeUri()) {
uri = uri.normalize();
}
// rfc2616 demands the location value be a complete URI
// Location = "Location" ":" absoluteURI
try { try {
if (config.isNormalizeUri()) {
uri = URIUtils.normalizeSyntax(uri);
}
// rfc2616 demands the location value be a complete URI
// Location = "Location" ":" absoluteURI
if (!uri.isAbsolute()) { if (!uri.isAbsolute()) {
if (!config.isRelativeRedirectsAllowed()) { if (!config.isRelativeRedirectsAllowed()) {
throw new ProtocolException("Relative redirect location '" throw new ProtocolException("Relative redirect location '"