DefaultRedirectStrategy to use URIUtils#normalizeSyntax method to normalize redirect location URI
This commit is contained in:
parent
4a463ebf4e
commit
be77dc917f
|
@ -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>();
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
try {
|
||||||
if (config.isNormalizeUri()) {
|
if (config.isNormalizeUri()) {
|
||||||
uri = uri.normalize();
|
uri = URIUtils.normalizeSyntax(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
// rfc2616 demands the location value be a complete URI
|
// rfc2616 demands the location value be a complete URI
|
||||||
// Location = "Location" ":" absoluteURI
|
// Location = "Location" ":" absoluteURI
|
||||||
try {
|
|
||||||
if (!uri.isAbsolute()) {
|
if (!uri.isAbsolute()) {
|
||||||
if (!config.isRelativeRedirectsAllowed()) {
|
if (!config.isRelativeRedirectsAllowed()) {
|
||||||
throw new ProtocolException("Relative redirect location '"
|
throw new ProtocolException("Relative redirect location '"
|
||||||
|
|
Loading…
Reference in New Issue