Search in sources :

Example 1 with HttpCookiePair

use of io.servicetalk.http.api.HttpCookiePair in project servicetalk by apple.

the class H2PriorKnowledgeFeatureParityTest method cookiesRoundTrip.

@ParameterizedTest(name = "{displayName} [{index}] client={0}, h2PriorKnowledge={1}")
@MethodSource("clientExecutors")
void cookiesRoundTrip(HttpTestExecutionStrategy strategy, boolean h2PriorKnowledge) throws Exception {
    setUp(strategy, h2PriorKnowledge);
    InetSocketAddress serverAddress = bindHttpEchoServer();
    try (BlockingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).buildBlocking()) {
        HttpRequest request = client.get("/");
        String requestCookie = "name1=value1; name2=value2; name3=value3";
        request.addHeader(COOKIE, requestCookie);
        HttpResponse response = client.request(request);
        CharSequence responseCookie = response.headers().get(COOKIE);
        assertNotNull(responseCookie);
        HttpCookiePair cookie = response.headers().getCookie("name1");
        assertNotNull(cookie);
        assertEquals("value1", cookie.value());
        cookie = response.headers().getCookie("name2");
        assertNotNull(cookie);
        assertEquals("value2", cookie.value());
        cookie = response.headers().getCookie("name3");
        assertNotNull(cookie);
        assertEquals("value3", cookie.value());
    }
}
Also used : HttpRequest(io.servicetalk.http.api.HttpRequest) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) InetSocketAddress(java.net.InetSocketAddress) HttpCookiePair(io.servicetalk.http.api.HttpCookiePair) DefaultHttpCookiePair(io.servicetalk.http.api.DefaultHttpCookiePair) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Matchers.emptyString(org.hamcrest.Matchers.emptyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with HttpCookiePair

use of io.servicetalk.http.api.HttpCookiePair in project servicetalk by apple.

the class H2ToStH1UtilsTest method testH1HeadersSplitCookieCrumbs.

void testH1HeadersSplitCookieCrumbs(HttpHeadersFactory headersFactory, CharSequence secondHeaderName) {
    HttpHeaders headers = headersFactory.newHeaders();
    // Add two headers which will be saved in the same entries[index]:
    headers.add(COOKIE, "a=b; c=d; e=f");
    String secondHeaderValue = "some-value";
    headers.add(secondHeaderName, secondHeaderValue);
    h1HeadersSplitCookieCrumbs(headers);
    List<HttpCookiePair> cookies = new ArrayList<>();
    for (HttpCookiePair pair : headers.getCookies()) {
        cookies.add(pair);
    }
    assertThat(cookies, hasSize(3));
    assertThat(cookies, containsInAnyOrder(new DefaultHttpCookiePair("a", "b"), new DefaultHttpCookiePair("c", "d"), new DefaultHttpCookiePair("e", "f")));
    assertThat(headers.get(secondHeaderName), equalTo(secondHeaderValue));
}
Also used : HttpHeaders(io.servicetalk.http.api.HttpHeaders) HttpCookiePair(io.servicetalk.http.api.HttpCookiePair) DefaultHttpCookiePair(io.servicetalk.http.api.DefaultHttpCookiePair) ArrayList(java.util.ArrayList) DefaultHttpCookiePair(io.servicetalk.http.api.DefaultHttpCookiePair)

Aggregations

DefaultHttpCookiePair (io.servicetalk.http.api.DefaultHttpCookiePair)2 HttpCookiePair (io.servicetalk.http.api.HttpCookiePair)2 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)1 HttpHeaders (io.servicetalk.http.api.HttpHeaders)1 HttpRequest (io.servicetalk.http.api.HttpRequest)1 HttpResponse (io.servicetalk.http.api.HttpResponse)1 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)1 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Matchers.emptyString (org.hamcrest.Matchers.emptyString)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1