use of mockwebserver3.RecordedRequest in project okhttp by square.
the class DnsOverHttpsTest method getIpv6.
@Test
public void getIpv6() throws Exception {
server.enqueue(dnsResponse("0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010001c00c00050001" + "00000a6d000603617069c012c0300005000100000cde000c04737461720463313072c012c04200010" + "0010000003b00049df00112"));
server.enqueue(dnsResponse("0000818000010003000000000567726170680866616365626f6f6b03636f6d00001c0001c00c00050001" + "00000a1b000603617069c012c0300005000100000b1f000c04737461720463313072c012c042001c0" + "0010000003b00102a032880f0290011faceb00c00000002"));
dns = buildLocalhost(bootstrapClient, true);
List<InetAddress> result = dns.lookup("google.com");
assertThat(result.size()).isEqualTo(2);
assertThat(result).contains(address("157.240.1.18"));
assertThat(result).contains(address("2a03:2880:f029:11:face:b00c:0:2"));
RecordedRequest request1 = server.takeRequest();
assertThat(request1.getMethod()).isEqualTo("GET");
RecordedRequest request2 = server.takeRequest();
assertThat(request2.getMethod()).isEqualTo("GET");
assertThat(asList(request1.getPath(), request2.getPath())).containsExactlyInAnyOrder("/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AAAEAAQ", "/lookup?ct&dns=AAABAAABAAAAAAAABmdvb2dsZQNjb20AABwAAQ");
}
use of mockwebserver3.RecordedRequest in project okhttp by square.
the class CacheTest method expirationDateInThePastWithLastModifiedHeader.
@Test
public void expirationDateInThePastWithLastModifiedHeader() throws Exception {
String lastModifiedDate = formatDate(-2, TimeUnit.HOURS);
RecordedRequest conditionalRequest = assertConditionallyCached(new MockResponse().addHeader("Last-Modified: " + lastModifiedDate).addHeader("Expires: " + formatDate(-1, TimeUnit.HOURS)));
assertThat(conditionalRequest.getHeader("If-Modified-Since")).isEqualTo(lastModifiedDate);
}
use of mockwebserver3.RecordedRequest in project okhttp by square.
the class CacheTest method maxAgeInThePastWithDateAndLastModifiedHeaders.
@Test
public void maxAgeInThePastWithDateAndLastModifiedHeaders() throws Exception {
String lastModifiedDate = formatDate(-2, TimeUnit.HOURS);
RecordedRequest conditionalRequest = assertConditionallyCached(new MockResponse().addHeader("Date: " + formatDate(-120, TimeUnit.SECONDS)).addHeader("Last-Modified: " + lastModifiedDate).addHeader("Cache-Control: max-age=60"));
assertThat(conditionalRequest.getHeader("If-Modified-Since")).isEqualTo(lastModifiedDate);
}
use of mockwebserver3.RecordedRequest in project okhttp by square.
the class CacheTest method clientSuppliedIfModifiedSinceWithCachedResult.
@Test
public void clientSuppliedIfModifiedSinceWithCachedResult() throws Exception {
MockResponse response = new MockResponse().addHeader("ETag: v3").addHeader("Cache-Control: max-age=0");
String ifModifiedSinceDate = formatDate(-24, TimeUnit.HOURS);
RecordedRequest request = assertClientSuppliedCondition(response, "If-Modified-Since", ifModifiedSinceDate);
assertThat(request.getHeader("If-Modified-Since")).isEqualTo(ifModifiedSinceDate);
assertThat(request.getHeader("If-None-Match")).isNull();
}
use of mockwebserver3.RecordedRequest in project okhttp by square.
the class CacheTest method defaultExpirationDateConditionallyCached.
@Test
public void defaultExpirationDateConditionallyCached() throws Exception {
// last modified: 115 seconds ago
// served: 15 seconds ago
// default lifetime: (115 - 15) / 10 = 10 seconds
// expires: 10 seconds from served date = 5 seconds ago
String lastModifiedDate = formatDate(-115, TimeUnit.SECONDS);
RecordedRequest conditionalRequest = assertConditionallyCached(new MockResponse().addHeader("Last-Modified: " + lastModifiedDate).addHeader("Date: " + formatDate(-15, TimeUnit.SECONDS)));
assertThat(conditionalRequest.getHeader("If-Modified-Since")).isEqualTo(lastModifiedDate);
}
Aggregations