use of zipkin2.Call in project okhttp by square.
the class HttpOverHttp2Test method readResponseHeaderTimeout.
@Test
public void readResponseHeaderTimeout() throws Exception {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE));
server.enqueue(new MockResponse().setBody("A"));
client = client.newBuilder().readTimeout(1000, MILLISECONDS).build();
// Make a call expecting a timeout reading the response headers.
Call call1 = client.newCall(new Request.Builder().url(server.url("/")).build());
try {
call1.execute();
fail("Should have timed out!");
} catch (SocketTimeoutException expected) {
assertEquals("timeout", expected.getMessage());
}
// Confirm that a subsequent request on the same connection is not impacted.
Call call2 = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response2 = call2.execute();
assertEquals("A", response2.body().string());
// Confirm that the connection was reused.
assertEquals(0, server.takeRequest().getSequenceNumber());
assertEquals(1, server.takeRequest().getSequenceNumber());
}
use of zipkin2.Call in project okhttp by square.
the class HttpOverHttp2Test method recoverFromOneRefusedStreamReusesConnection.
@Test
public void recoverFromOneRefusedStreamReusesConnection() throws Exception {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.RESET_STREAM_AT_START).setHttp2ErrorCode(ErrorCode.REFUSED_STREAM.httpCode));
server.enqueue(new MockResponse().setBody("abc"));
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response = call.execute();
assertEquals("abc", response.body().string());
// New connection.
assertEquals(0, server.takeRequest().getSequenceNumber());
// Reused connection.
assertEquals(1, server.takeRequest().getSequenceNumber());
}
use of zipkin2.Call in project okhttp by square.
the class HttpOverHttp2Test method serverSendsPushPromise_HEAD.
@Test
public void serverSendsPushPromise_HEAD() throws Exception {
PushPromise pushPromise = new PushPromise("HEAD", "/foo/bar", Headers.of("foo", "bar"), new MockResponse().setStatus("HTTP/1.1 204 Sweet"));
server.enqueue(new MockResponse().setBody("ABCDE").setStatus("HTTP/1.1 200 Sweet").withPush(pushPromise));
Call call = client.newCall(new Request.Builder().url(server.url("/foo")).build());
Response response = call.execute();
assertEquals("ABCDE", response.body().string());
assertEquals(200, response.code());
assertEquals("Sweet", response.message());
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
assertEquals("https", request.getHeader(":scheme"));
assertEquals(server.getHostName() + ":" + server.getPort(), request.getHeader(":authority"));
RecordedRequest pushedRequest = server.takeRequest();
assertEquals("HEAD /foo/bar HTTP/1.1", pushedRequest.getRequestLine());
assertEquals("bar", pushedRequest.getHeader("foo"));
}
use of zipkin2.Call in project okhttp by square.
the class HttpOverHttp2Test method settingsLimitsMaxConcurrentStreams.
/**
* Push a setting that permits up to 2 concurrent streams, then make 3 concurrent requests and
* confirm that the third concurrent request prepared a new connection.
*/
@Test
public void settingsLimitsMaxConcurrentStreams() throws Exception {
Settings settings = new Settings();
settings.set(Settings.MAX_CONCURRENT_STREAMS, 2);
// Read & write a full request to confirm settings are accepted.
server.enqueue(new MockResponse().withSettings(settings));
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response = call.execute();
assertEquals("", response.body().string());
server.enqueue(new MockResponse().setBody("ABC"));
server.enqueue(new MockResponse().setBody("DEF"));
server.enqueue(new MockResponse().setBody("GHI"));
Call call1 = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response1 = call1.execute();
Call call2 = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response2 = call2.execute();
Call call3 = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response3 = call3.execute();
assertEquals("ABC", response1.body().string());
assertEquals("DEF", response2.body().string());
assertEquals("GHI", response3.body().string());
// Settings connection.
assertEquals(0, server.takeRequest().getSequenceNumber());
// Reuse settings connection.
assertEquals(1, server.takeRequest().getSequenceNumber());
// Reuse settings connection.
assertEquals(2, server.takeRequest().getSequenceNumber());
// New connection!
assertEquals(0, server.takeRequest().getSequenceNumber());
}
use of zipkin2.Call in project okhttp by square.
the class HttpOverHttp2Test method domainFronting.
/** https://github.com/square/okhttp/issues/3103 */
@Test
public void domainFronting() throws Exception {
client = client.newBuilder().addNetworkInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request().newBuilder().header("Host", "privateobject.com").build();
return chain.proceed(request);
}
}).build();
server.enqueue(new MockResponse());
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response = call.execute();
assertEquals("", response.body().string());
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("privateobject.com", recordedRequest.getHeader(":authority"));
}
Aggregations