File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
main/java/com/google/api/client/http
test/java/com/google/api/client/http Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 2121import com .google .common .base .Preconditions ;
2222
2323import java .io .ByteArrayOutputStream ;
24+ import java .io .EOFException ;
2425import java .io .IOException ;
2526import java .io .InputStream ;
2627import java .io .OutputStream ;
@@ -377,6 +378,9 @@ public InputStream getContent() throws IOException {
377378 }
378379 content = lowLevelResponseContent ;
379380 contentProcessed = true ;
381+ } catch (EOFException e ) {
382+ // this may happen for example on a HEAD request since there no actual response data read
383+ // in GZIPInputStream
380384 } finally {
381385 if (!contentProcessed ) {
382386 lowLevelResponseContent .close ();
Original file line number Diff line number Diff line change @@ -390,4 +390,25 @@ public LowLevelHttpResponse execute() throws IOException {
390390 response .parseAsString ();
391391 recorder .assertMessages (expectedMessages );
392392 }
393+
394+ public void testGetContent_gzipNoContent () throws IOException {
395+ HttpTransport transport = new MockHttpTransport () {
396+ @ Override
397+ public LowLevelHttpRequest buildRequest (String method , final String url ) throws IOException {
398+ return new MockLowLevelHttpRequest () {
399+ @ Override
400+ public LowLevelHttpResponse execute () throws IOException {
401+ MockLowLevelHttpResponse result = new MockLowLevelHttpResponse ();
402+ result .setContent ("" );
403+ result .setContentEncoding ("gzip" );
404+ result .setContentType ("text/plain" );
405+ return result ;
406+ }
407+ };
408+ }
409+ };
410+ HttpRequest request =
411+ transport .createRequestFactory ().buildHeadRequest (HttpTesting .SIMPLE_GENERIC_URL );
412+ request .execute ().getContent ();
413+ }
393414}
You can’t perform that action at this time.
0 commit comments