/** * Returns true if the response must have a (possibly 0-length) body. See RFC 2616 section 4.3. */ public final boolean hasResponseBody() { int responseCode = responseHeaders.getHeaders().getResponseCode(); // HEAD requests never yield a body regardless of the response headers. if (method.equals("HEAD")) { return false; } if ((responseCode < HTTP_CONTINUE || responseCode >= 200) && responseCode != HttpURLConnectionImpl.HTTP_NO_CONTENT && responseCode != HttpURLConnectionImpl.HTTP_NOT_MODIFIED) { return true; } // If the Content-Length or Transfer-Encoding headers disagree with the // response code, the response is malformed. For best compatibility, we // honor the headers. if (responseHeaders.getContentLength() != -1 || responseHeaders.isChunked()) { return true; } return false; }
public final int getResponseCode() { if (responseHeaders == null) { throw new IllegalStateException(); } return responseHeaders.getHeaders().getResponseCode(); }