"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java" between
httpcomponents-client-4.5.7-src.tar.gz and httpcomponents-client-4.5.8-src.tar.gz

About: HttpComponents is an Apache project responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols. Java sources.

DefaultRedirectStrategy.java  (httpcomponents-client-4.5.7-src):DefaultRedirectStrategy.java  (httpcomponents-client-4.5.8-src)
skipping to change at line 32 skipping to change at line 32
* individuals on behalf of the Apache Software Foundation. For more * individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
* *
*/ */
package org.apache.http.impl.client; package org.apache.http.impl.client;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Locale;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.HttpRequest; import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.ProtocolException; import org.apache.http.ProtocolException;
import org.apache.http.annotation.Contract; import org.apache.http.annotation.Contract;
import org.apache.http.annotation.ThreadingBehavior; import org.apache.http.annotation.ThreadingBehavior;
import org.apache.http.client.CircularRedirectException; import org.apache.http.client.CircularRedirectException;
import org.apache.http.client.RedirectStrategy; import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead; import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder; import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.client.utils.URIUtils; import org.apache.http.client.utils.URIUtils;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args; import org.apache.http.util.Args;
import org.apache.http.util.Asserts; import org.apache.http.util.Asserts;
import org.apache.http.util.TextUtils;
/** /**
* Default implementation of {@link RedirectStrategy}. This strategy honors the restrictions * Default implementation of {@link RedirectStrategy}. This strategy honors the restrictions
* on automatic redirection of entity enclosing methods such as POST and PUT imp osed by the * on automatic redirection of entity enclosing methods such as POST and PUT imp osed by the
* HTTP specification. {@code 302 Moved Temporarily}, {@code 301 Moved Permanent ly} and * HTTP specification. {@code 302 Moved Temporarily}, {@code 301 Moved Permanent ly} and
* {@code 307 Temporary Redirect} status codes will result in an automatic redir ect of * {@code 307 Temporary Redirect} status codes will result in an automatic redir ect of
* HEAD and GET methods only. POST and PUT methods will not be automatically red irected * HEAD and GET methods only. POST and PUT methods will not be automatically red irected
* as requiring user confirmation. * as requiring user confirmation.
* <p> * <p>
* The restriction on automatic redirection of POST methods can be relaxed by us ing * The restriction on automatic redirection of POST methods can be relaxed by us ing
skipping to change at line 150 skipping to change at line 147
} }
final String location = locationHeader.getValue(); final String location = locationHeader.getValue();
if (this.log.isDebugEnabled()) { if (this.log.isDebugEnabled()) {
this.log.debug("Redirect requested to location '" + location + "'"); this.log.debug("Redirect requested to location '" + location + "'");
} }
final RequestConfig config = clientContext.getRequestConfig(); final RequestConfig config = clientContext.getRequestConfig();
URI uri = createLocationURI(location); URI uri = createLocationURI(location);
// 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 '"
+ uri + "' not allowed"); + uri + "' not allowed");
} }
// Adjust location URI // Adjust location URI
final HttpHost target = clientContext.getTargetHost(); final HttpHost target = clientContext.getTargetHost();
Asserts.notNull(target, "Target host"); Asserts.notNull(target, "Target host");
final URI requestURI = new URI(request.getRequestLine().getUri() ); final URI requestURI = new URI(request.getRequestLine().getUri() );
final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, t final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, t
arget, false); arget,
config.isNormalizeUri() ? URIUtils.NORMALIZE : URIUtils.NO_F
LAGS);
uri = URIUtils.resolve(absoluteRequestURI, uri); uri = URIUtils.resolve(absoluteRequestURI, uri);
} }
} catch (final URISyntaxException ex) { } catch (final URISyntaxException ex) {
throw new ProtocolException(ex.getMessage(), ex); throw new ProtocolException(ex.getMessage(), ex);
} }
RedirectLocations redirectLocations = (RedirectLocations) clientContext. getAttribute( RedirectLocations redirectLocations = (RedirectLocations) clientContext. getAttribute(
HttpClientContext.REDIRECT_LOCATIONS); HttpClientContext.REDIRECT_LOCATIONS);
if (redirectLocations == null) { if (redirectLocations == null) {
redirectLocations = new RedirectLocations(); redirectLocations = new RedirectLocations();
skipping to change at line 189 skipping to change at line 191
} }
redirectLocations.add(uri); redirectLocations.add(uri);
return uri; return uri;
} }
/** /**
* @since 4.1 * @since 4.1
*/ */
protected URI createLocationURI(final String location) throws ProtocolExcept ion { protected URI createLocationURI(final String location) throws ProtocolExcept ion {
try { try {
final URIBuilder b = new URIBuilder(new URI(location).normalize()); return new URI(location);
final String host = b.getHost();
if (host != null) {
b.setHost(host.toLowerCase(Locale.ROOT));
}
final String path = b.getPath();
if (TextUtils.isEmpty(path)) {
b.setPath("/");
}
return b.build();
} catch (final URISyntaxException ex) { } catch (final URISyntaxException ex) {
throw new ProtocolException("Invalid redirect URI: " + location, ex) ; throw new ProtocolException("Invalid redirect URI: " + location, ex) ;
} }
} }
/** /**
* @since 4.2 * @since 4.2
*/ */
protected boolean isRedirectable(final String method) { protected boolean isRedirectable(final String method) {
for (final String m: REDIRECT_METHODS) { for (final String m: REDIRECT_METHODS) {
 End of changes. 7 change blocks. 
17 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)