Search in sources :

Example 21 with RecordedRequest

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");
}
Also used : RecordedRequest(mockwebserver3.RecordedRequest) InetAddress(java.net.InetAddress) Test(org.junit.jupiter.api.Test)

Example 22 with RecordedRequest

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);
}
Also used : RecordedRequest(mockwebserver3.RecordedRequest) MockResponse(mockwebserver3.MockResponse) Test(org.junit.jupiter.api.Test)

Example 23 with RecordedRequest

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);
}
Also used : RecordedRequest(mockwebserver3.RecordedRequest) MockResponse(mockwebserver3.MockResponse) Test(org.junit.jupiter.api.Test)

Example 24 with RecordedRequest

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();
}
Also used : RecordedRequest(mockwebserver3.RecordedRequest) MockResponse(mockwebserver3.MockResponse) Test(org.junit.jupiter.api.Test)

Example 25 with RecordedRequest

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);
}
Also used : RecordedRequest(mockwebserver3.RecordedRequest) MockResponse(mockwebserver3.MockResponse) Test(org.junit.jupiter.api.Test)

Aggregations

RecordedRequest (mockwebserver3.RecordedRequest)30 MockResponse (mockwebserver3.MockResponse)26 Test (org.junit.jupiter.api.Test)25 CookieManager (java.net.CookieManager)5 InetAddress (java.net.InetAddress)5 URI (java.net.URI)3 Arrays.asList (java.util.Arrays.asList)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 Map (java.util.Map)3 MockWebServer (mockwebserver3.MockWebServer)3 HttpCookie (java.net.HttpCookie)2 Dispatcher (mockwebserver3.Dispatcher)2 Cache (okhttp3.Cache)2 OkHttpClient (okhttp3.OkHttpClient)2 WebSocket (okhttp3.WebSocket)2 Buffer (okio.Buffer)2 File (java.io.File)1 IOException (java.io.IOException)1 CookieHandler (java.net.CookieHandler)1