use of mockwebserver3.MockResponse in project okhttp by square.
the class ConnectionCoalescingTest method worksWithNetworkInterceptors.
/**
* Network interceptors check for changes to target.
*/
@Test
public void worksWithNetworkInterceptors() throws Exception {
client = client.newBuilder().addNetworkInterceptor(chain -> chain.proceed(chain.request())).build();
server.enqueue(new MockResponse());
server.enqueue(new MockResponse());
assert200Http2Response(execute(url), server.getHostName());
HttpUrl sanUrl = url.newBuilder().host("san.com").build();
assert200Http2Response(execute(sanUrl), "san.com");
assertThat(client.connectionPool().connectionCount()).isEqualTo(1);
}
use of mockwebserver3.MockResponse in project okhttp by square.
the class ConnectionCoalescingTest method alternativeThenCommon.
/**
* Test connecting to an alternative host then common name, although only subject alternative
* names are used if present no special consideration of common name.
*/
@Test
public void alternativeThenCommon() throws Exception {
server.enqueue(new MockResponse());
server.enqueue(new MockResponse());
HttpUrl sanUrl = url.newBuilder().host("san.com").build();
assert200Http2Response(execute(sanUrl), "san.com");
assert200Http2Response(execute(url), server.getHostName());
assertThat(client.connectionPool().connectionCount()).isEqualTo(1);
}
use of mockwebserver3.MockResponse in project okhttp by square.
the class ConnectionCoalescingTest method skipsWhenDnsDontMatch.
/**
* If the existing connection matches a SAN but not a match for DNS then skip.
*/
@Test
public void skipsWhenDnsDontMatch() throws Exception {
server.enqueue(new MockResponse());
assert200Http2Response(execute(url), server.getHostName());
HttpUrl differentDnsUrl = url.newBuilder().host("differentdns.com").build();
try {
execute(differentDnsUrl);
fail("expected a failed attempt to connect");
} catch (IOException expected) {
}
}
use of mockwebserver3.MockResponse in project okhttp by square.
the class HttpLoggingInterceptorTest method bodyGetNoBody.
private void bodyGetNoBody(int code) throws IOException {
server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + code + " No Content"));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs.assertLogEqual("--> GET " + url).assertLogEqual("--> END GET").assertLogMatch("<-- " + code + " No Content " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("--> END GET").assertLogMatch("<-- " + code + " No Content " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
}
use of mockwebserver3.MockResponse in project okhttp by square.
the class HttpLoggingInterceptorTest method headersResponseBody.
@Test
public void headersResponseBody() throws IOException {
setLevel(Level.HEADERS);
server.enqueue(new MockResponse().setBody("Hello!").setHeader("Content-Type", PLAIN));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs.assertLogEqual("--> GET " + url).assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 6").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 6").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
}
Aggregations