use of mockwebserver3.RecordedRequest in project okhttp by square.
the class WebSocketHttpTest method readTimeoutAppliesWithinFrames.
/**
* There's no read timeout when reading the first byte of a new frame. But as soon as we start
* reading a frame we enable the read timeout. In this test we have the server returning the first
* byte of a frame but no more frames.
*/
@Test
public void readTimeoutAppliesWithinFrames() {
webServer.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) {
return upgradeResponse(request).setBody(// Truncated frame.
new Buffer().write(ByteString.decodeHex("81"))).removeHeader("Content-Length").setSocketPolicy(SocketPolicy.KEEP_OPEN);
}
});
WebSocket webSocket = newWebSocket();
clientListener.assertOpen();
clientListener.assertFailure(SocketTimeoutException.class, "timeout", "Read timed out");
assertThat(webSocket.close(1000, null)).isFalse();
}
use of mockwebserver3.RecordedRequest in project okhttp by square.
the class CacheTest method assertClientSuppliedCondition.
private RecordedRequest assertClientSuppliedCondition(MockResponse seed, String conditionName, String conditionValue) throws Exception {
server.enqueue(seed.setBody("A"));
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
HttpUrl url = server.url("/");
assertThat(get(url).body().string()).isEqualTo("A");
Request request = new Request.Builder().url(url).header(conditionName, conditionValue).build();
Response response = client.newCall(request).execute();
assertThat(response.code()).isEqualTo(HttpURLConnection.HTTP_NOT_MODIFIED);
assertThat(response.body().string()).isEqualTo("");
// seed
server.takeRequest();
return server.takeRequest();
}
use of mockwebserver3.RecordedRequest in project okhttp by square.
the class DnsOverHttpsTest method failure.
@Test
public void failure() throws Exception {
server.enqueue(dnsResponse("0000818300010000000100000e7364666c6b686673646c6b6a64660265650000010001c01b00060001" + "000007070038026e7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e657" + "4c01b5adb12c100000e10000003840012750000000e10"));
try {
dns.lookup("google.com");
fail();
} catch (UnknownHostException uhe) {
uhe.printStackTrace();
assertThat(uhe.getMessage()).isEqualTo("google.com: NXDOMAIN");
}
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ");
}
use of mockwebserver3.RecordedRequest in project okhttp by square.
the class DnsOverHttpsTest method usesCacheOnlyIfFresh.
@Test
public void usesCacheOnlyIfFresh() throws Exception {
Cache cache = new Cache(new File("./target/DnsOverHttpsTest.cache"), 100 * 1024);
OkHttpClient cachedClient = bootstrapClient.newBuilder().cache(cache).build();
DnsOverHttps cachedDns = buildLocalhost(cachedClient, false);
server.enqueue(dnsResponse("0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010001c00c00050001" + "00000a6d000603617069c012c0300005000100000cde000c04737461720463313072c012c04200010" + "0010000003b00049df00112").setHeader("cache-control", "max-age=1"));
List<InetAddress> result = cachedDns.lookup("google.com");
assertThat(result).containsExactly(address("157.240.1.18"));
RecordedRequest recordedRequest = server.takeRequest(0, TimeUnit.SECONDS);
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ");
Thread.sleep(2000);
server.enqueue(dnsResponse("0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010001c00c00050001" + "00000a6d000603617069c012c0300005000100000cde000c04737461720463313072c012c04200010" + "0010000003b00049df00112").setHeader("cache-control", "max-age=1"));
result = cachedDns.lookup("google.com");
assertThat(result).isEqualTo(singletonList(address("157.240.1.18")));
recordedRequest = server.takeRequest(0, TimeUnit.SECONDS);
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ");
}
use of mockwebserver3.RecordedRequest in project okhttp by square.
the class DnsOverHttpsTest method getOne.
@Test
public void getOne() throws Exception {
server.enqueue(dnsResponse("0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010001c00c00050001" + "00000a6d000603617069c012c0300005000100000cde000c04737461720463313072c012c04200010" + "0010000003b00049df00112"));
List<InetAddress> result = dns.lookup("google.com");
assertThat(result).isEqualTo(singletonList(address("157.240.1.18")));
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getMethod()).isEqualTo("GET");
assertThat(recordedRequest.getPath()).isEqualTo("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ");
}
Aggregations