mirror of
https://github.com/square/okhttp.git
synced 2026-01-18 20:40:58 +03:00
Close the source after reading regardless of result.
This commit is contained in:
@@ -189,7 +189,6 @@ public class JavaApiConverterTest {
|
||||
assertEquals("Fantastic", response.message());
|
||||
Headers okResponseHeaders = response.headers();
|
||||
assertEquals("baz", okResponseHeaders.get("xyzzy"));
|
||||
assertEquals(body, response.body().string());
|
||||
if (isSecure) {
|
||||
Handshake handshake = response.handshake();
|
||||
assertNotNull(handshake);
|
||||
@@ -204,6 +203,7 @@ public class JavaApiConverterTest {
|
||||
} else {
|
||||
assertNull(response.handshake());
|
||||
}
|
||||
assertEquals(body, response.body().string());
|
||||
}
|
||||
|
||||
@Test public void createOkResponse_fromCacheResponse() throws Exception {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.squareup.okhttp;
|
||||
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import com.squareup.okhttp.internal.http.OkHeaders;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@@ -205,8 +206,14 @@ public final class Response {
|
||||
// }
|
||||
// return bytes;
|
||||
|
||||
BufferedSource source = source();
|
||||
Buffer buffer = new Buffer();
|
||||
long contentRead = buffer.writeAll(source());
|
||||
long contentRead;
|
||||
try {
|
||||
contentRead = buffer.writeAll(source);
|
||||
} finally {
|
||||
Util.closeQuietly(source);
|
||||
}
|
||||
if (contentLength != -1 && contentLength != contentRead) {
|
||||
throw new IOException("Content-Length and stream length disagree");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user