File tree 3 files changed +40
-0
lines changed
main/java/com/google/api/client
test/java/com/google/api/client/http/javanet
3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,9 @@ LowLevelHttpResponse execute(final OutputWriter outputWriter) throws IOException
141
141
Preconditions .checkArgument (
142
142
contentLength == 0 , "%s with non-zero content length is not supported" , requestMethod );
143
143
}
144
+ } else if ("DELETE" .equals (connection .getRequestMethod ())) {
145
+ connection .setDoOutput (true );
146
+ connection .setFixedLengthStreamingMode (0L );
144
147
}
145
148
// connect
146
149
boolean successfulConnection = false ;
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ public class MockHttpURLConnection extends HttpURLConnection {
42
42
43
43
/** Whether {@link #doOutput} was called. */
44
44
private boolean doOutputCalled ;
45
+ /** Whether {@link #setFixedLengthStreamingMode(int)} was called. */
46
+ private boolean setFixedLengthStreamingModeIntCalled = false ;
47
+ /** Whether {@link #setFixedLengthStreamingMode(long)} was called. */
48
+ private boolean setFixedLengthStreamingModeLongCalled = false ;
45
49
46
50
/**
47
51
* Output stream or {@code null} to throw an {@link UnknownServiceException} when {@link
@@ -205,4 +209,24 @@ public String getHeaderField(String name) {
205
209
public int getChunkLength () {
206
210
return chunkLength ;
207
211
}
212
+
213
+ @ Override
214
+ public void setFixedLengthStreamingMode (int contentLength ) {
215
+ this .setFixedLengthStreamingModeIntCalled = true ;
216
+ super .setFixedLengthStreamingMode (contentLength );
217
+ }
218
+
219
+ @ Override
220
+ public void setFixedLengthStreamingMode (long contentLength ) {
221
+ this .setFixedLengthStreamingModeLongCalled = true ;
222
+ super .setFixedLengthStreamingMode (contentLength );
223
+ }
224
+
225
+ public boolean isSetFixedLengthStreamingModeIntCalled () {
226
+ return setFixedLengthStreamingModeIntCalled ;
227
+ }
228
+
229
+ public boolean isSetFixedLengthStreamingModeLongCalled () {
230
+ return setFixedLengthStreamingModeLongCalled ;
231
+ }
208
232
}
Original file line number Diff line number Diff line change @@ -233,4 +233,17 @@ public void testChunkedLengthNotSet() throws Exception {
233
233
assertEquals (connection .getChunkLength (), -1 );
234
234
assertEquals ("6" , request .getRequestProperty ("Content-Length" ));
235
235
}
236
+
237
+ // see https://github.com/googleapis/google-http-java-client/issues/1471 for more details
238
+ @ Test
239
+ public void testDeleteSetsContentLengthToZeroWithoutContent () throws Exception {
240
+ MockHttpURLConnection connection = new MockHttpURLConnection (new URL (HttpTesting .SIMPLE_URL ));
241
+ connection .setRequestMethod ("DELETE" );
242
+ NetHttpRequest request = new NetHttpRequest (connection );
243
+ request .execute ();
244
+
245
+ assertTrue (connection .doOutputCalled ());
246
+ assertTrue (connection .isSetFixedLengthStreamingModeLongCalled ());
247
+ assertFalse (connection .isSetFixedLengthStreamingModeIntCalled ());
248
+ }
236
249
}
You can’t perform that action at this time.
0 commit comments