artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

Leaks in NetHttpResponse #235

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The current implementation of NetHttpResponse returns the input stream only if 
the status code is successful. But the right implementation should be in case 
the status code is less or equal to 400.

@Override
 public InputStream getContent() throws IOException {
   HttpURLConnection connection = this.connection;
   return HttpStatusCodes.isSuccess(responseCode)
       ? connection.getInputStream() : connection.getErrorStream();
 }

Because HttpURLConnection implementation:
1674    @Override
1675    public InputStream More ...getErrorStream() {
1676        if (connected && responseCode >= 400) {
1677            // Client Error 4xx and Server Error 5xx
1678            if (errorStream != null) {
1679                return errorStream;
1680            } else if (inputStream != null) {
1681                return inputStream;
1682            }
1683        }
1684        return null;
1685    }

Original issue reported on code.google.com by pele...@google.com on 17 Jul 2013 at 7:52

GoogleCodeExporter commented 9 years ago

Original comment by pele...@google.com on 17 Jul 2013 at 7:52

GoogleCodeExporter commented 9 years ago
https://codereview.appspot.com/11472043/

Original comment by yan...@google.com on 19 Jul 2013 at 11:52

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 19 Jul 2013 at 11:52

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 26 Jul 2013 at 10:03

GoogleCodeExporter commented 9 years ago

Original comment by pele...@google.com on 7 Aug 2013 at 7:09