Skip to content

Commit 3367002

Browse files
committed
http Issue 225: When redirects on 303 are changed to GET, they must have empty
content https://code.google.com/p/google-http-java-client/issues/detail?id=225 https://codereview.appspot.com/13094046/
1 parent 882d8a3 commit 3367002

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

google-http-client/src/main/java/com/google/api/client/http/HttpRequest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,12 @@ public Future<HttpResponse> executeAsync() {
11021102
* {@code "If-*"} request headers.
11031103
* </p>
11041104
*
1105+
* <p>
1106+
* Upgrade warning: When handling a status code of 303, {@link #handleRedirect(int, HttpHeaders)}
1107+
* now correctly removes any content from the body of the new request, as GET requests should not
1108+
* have content. It did not do this in prior version 1.16.
1109+
* </p>
1110+
*
11051111
* @return whether the redirect was successful
11061112
* @since 1.11
11071113
*/
@@ -1114,6 +1120,8 @@ public boolean handleRedirect(int statusCode, HttpHeaders responseHeaders) {
11141120
// on 303 change method to GET
11151121
if (statusCode == HttpStatusCodes.STATUS_CODE_SEE_OTHER) {
11161122
setRequestMethod(HttpMethods.GET);
1123+
// GET requests do not support non-zero content length
1124+
setContent(null);
11171125
}
11181126
// remove Authorization and If-* headers
11191127
headers.setAuthorization((String) null);

google-http-client/src/test/java/com/google/api/client/http/HttpRequestTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import com.google.api.client.testing.http.MockHttpUnsuccessfulResponseHandler;
2020
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
2121
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
22+
import com.google.api.client.testing.util.LogRecordingHandler;
2223
import com.google.api.client.testing.util.MockBackOff;
2324
import com.google.api.client.testing.util.MockSleeper;
2425
import com.google.api.client.util.BackOff;
25-
import com.google.api.client.testing.util.LogRecordingHandler;
2626
import com.google.api.client.util.Key;
2727
import com.google.api.client.util.LoggingStreamingContent;
2828
import com.google.api.client.util.StringUtils;
@@ -319,6 +319,8 @@ public void test303Redirect() throws Exception {
319319
Assert.assertEquals(2, fakeTransport.lowLevelExecCalls);
320320
// Assert that the method in the request was changed to a GET due to the 303.
321321
Assert.assertEquals(HttpMethods.GET, request.getRequestMethod());
322+
// Assert that the content is null, since GET requests don't support non-zero content-length
323+
Assert.assertNull(request.getContent());
322324
}
323325

324326
public void testInfiniteRedirects() throws Exception {

0 commit comments

Comments
 (0)