1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-18 20:40:58 +03:00

Don't NPE after a redirect.

We were releasing the connection (to the successor request) and
later attempting to close the null connection.
This commit is contained in:
Jesse Wilson
2014-05-19 22:14:20 -04:00
parent 3d0d59c2b7
commit 3bf2e37122
2 changed files with 7 additions and 8 deletions

View File

@@ -60,15 +60,14 @@ public final class Response {
}
/**
* The wire-level request that initiated this HTTP response. This is usually
* <strong>not</strong> the same request instance provided to the HTTP client:
* The wire-level request that initiated this HTTP response. This is not
* necessarily the same request issued by the application:
* <ul>
* <li>It may be transformed by the HTTP client. For example, the client
* may have added its own {@code Content-Encoding} header to enable
* response compression.
* <li>It may be the request generated in response to an HTTP redirect.
* In this case the request URL may be different than the initial
* request URL.
* may copy headers like {@code Content-Length} from the request body.
* <li>It may be the request generated in response to an HTTP redirect or
* authentication challenge. In this case the request URL may be
* different than the initial request URL.
* </ul>
*/
public Request request() {

View File

@@ -509,7 +509,7 @@ public final class HttpEngine {
closeQuietly(responseBodyBytes);
// Close the connection if it cannot be reused.
if (transport != null && !transport.canReuseConnection()) {
if (transport != null && connection != null && !transport.canReuseConnection()) {
closeQuietly(connection.getSocket());
connection = null;
return null;