Search in sources :

Example 31 with RecordedRequest

use of mockwebserver3.RecordedRequest in project okhttp by square.

the class CookiesTest method testQuoteStripping.

@Test
public void testQuoteStripping() throws Exception {
    client = client.newBuilder().cookieJar(new JavaNetCookieJar(new CookieManager() {

        @Override
        public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) {
            Map<String, List<String>> result = new LinkedHashMap<>();
            result.put("COOKIE", Collections.singletonList("Bar=\""));
            result.put("cooKIE2", Collections.singletonList("Baz=\"baz\""));
            return result;
        }
    })).build();
    server.enqueue(new MockResponse());
    get(server.url("/"));
    RecordedRequest request = server.takeRequest();
    assertThat(request.getHeader("Cookie")).isEqualTo("Bar=\"; Baz=baz");
    assertThat(request.getHeader("Cookie2")).isNull();
    assertThat(request.getHeader("Quux")).isNull();
}
Also used : RecordedRequest(mockwebserver3.RecordedRequest) MockResponse(mockwebserver3.MockResponse) List(java.util.List) Arrays.asList(java.util.Arrays.asList) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CookieManager(java.net.CookieManager) LinkedHashMap(java.util.LinkedHashMap) 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