1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-24 04:02:07 +03:00

add read response header timeout case

This commit is contained in:
lingming.yb
2014-01-04 11:48:49 +08:00
parent 139374624c
commit 1cfab33333
3 changed files with 22 additions and 1 deletions

View File

@@ -690,6 +690,9 @@ public final class MockWebServer {
}
private void writeResponse(SpdyStream stream, MockResponse response) throws IOException {
if (response.getSocketPolicy() == SocketPolicy.NO_RESPONSE) {
return;
}
List<String> spdyHeaders = new ArrayList<String>();
String[] statusParts = response.getStatus().split(" ", 2);
if (statusParts.length != 2) {

View File

@@ -57,5 +57,11 @@ public enum SocketPolicy {
* Shutdown the socket output after sending the response. For testing bad
* behavior.
*/
SHUTDOWN_OUTPUT_AT_END
SHUTDOWN_OUTPUT_AT_END,
/**
* Don't response to the request but keep the socket open. For testing
* read response header timeout issue.
*/
NO_RESPONSE
}

View File

@@ -23,6 +23,8 @@ import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;
import com.squareup.okhttp.mockwebserver.SocketPolicy;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -226,6 +228,16 @@ public final class HttpOverSpdyTest {
assertEquals(-1, in.read());
}
@Test(timeout = 3000) public void readResponseHeaderTimeout() throws Exception {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE));
server.enqueue(new MockResponse().setBody("A"));
server.play();
HttpURLConnection connection = client.open(server.getUrl("/"));
connection.setReadTimeout(1000);
assertContent("A", connection, Integer.MAX_VALUE);
}
@Test public void responsesAreCached() throws IOException {
client.setResponseCache(cache);