On 10 October 2012 21:51, <[email protected]> wrote: > Author: olegk > Date: Wed Oct 10 20:51:30 2012 > New Revision: 1396793 > > URL: http://svn.apache.org/viewvc?rev=1396793&view=rev > Log: > HTTPCLIENT-1248: Default and lax redirect strategies should not convert > requests redirected with 307 status to GET method > > Modified: > httpcomponents/httpclient/trunk/RELEASE_NOTES.txt > > httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java > > httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java > > Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt > URL: > http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1396793&r1=1396792&r2=1396793&view=diff > ============================================================================== > --- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original) > +++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Wed Oct 10 20:51:30 2012 > @@ -1,6 +1,10 @@ > Changes since 4.2.1 > ------------------- > > +* [HTTPCLIENT-1248]: Default and lax redirect strategies should not convert > requests redirected > + with 307 status to GET method. > + Contributed by Oleg Kalnichevski <olegk at apache.org> > + > * [HTTPCLIENT-1215] BasicAuthCache does not take default ports into > consideration when > looking up cached authentication details by HttpHost key. > Contributed by Oleg Kalnichevski <olegk at apache.org> > > Modified: > httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java > URL: > http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java?rev=1396793&r1=1396792&r2=1396793&view=diff > ============================================================================== > --- > httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java > (original) > +++ > httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java > Wed Oct 10 20:51:30 2012 > @@ -35,6 +35,7 @@ import org.apache.http.annotation.Immuta > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > import org.apache.http.Header; > +import org.apache.http.HttpEntityEnclosingRequest; > import org.apache.http.HttpHost; > import org.apache.http.HttpRequest; > import org.apache.http.HttpResponse; > @@ -42,8 +43,15 @@ import org.apache.http.HttpStatus; > import org.apache.http.ProtocolException; > import org.apache.http.client.CircularRedirectException; > import org.apache.http.client.RedirectStrategy; > +import org.apache.http.client.methods.HttpDelete; > +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; > import org.apache.http.client.methods.HttpGet; > import org.apache.http.client.methods.HttpHead; > +import org.apache.http.client.methods.HttpOptions; > +import org.apache.http.client.methods.HttpPatch; > +import org.apache.http.client.methods.HttpPost; > +import org.apache.http.client.methods.HttpPut; > +import org.apache.http.client.methods.HttpTrace; > import org.apache.http.client.methods.HttpUriRequest; > import org.apache.http.client.params.ClientPNames; > import org.apache.http.client.utils.URIUtils; > @@ -210,9 +218,35 @@ public class DefaultRedirectStrategy imp > String method = request.getRequestLine().getMethod(); > if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) { > return new HttpHead(uri); > + } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) { > + return new HttpGet(uri); > } else { > + int status = response.getStatusLine().getStatusCode(); > + if (status == HttpStatus.SC_TEMPORARY_REDIRECT) { > + if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) { > + return copyEntity(new HttpPost(uri), request); > + } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) { > + return copyEntity(new HttpPut(uri), request); > + } else if (method.equalsIgnoreCase(HttpDelete.METHOD_NAME)) { > + return new HttpDelete(uri); > + } else if (method.equalsIgnoreCase(HttpTrace.METHOD_NAME)) { > + return new HttpTrace(uri); > + } else if (method.equalsIgnoreCase(HttpOptions.METHOD_NAME)) > { > + return new HttpOptions(uri); > + } else if (method.equalsIgnoreCase(HttpPatch.METHOD_NAME)) { > + return copyEntity(new HttpPatch(uri), request); > + } > + } > return new HttpGet(uri);
The above code converts unknown methods into GET. If a new method is added, that will be incorrect. It might be useful to know when this is happening; maybe an assert would be useful here? Or a log message? Or is it possible to write a clone/copy method that works for all possible methods? Maybe methods should know how to clone themselves? --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
