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());
}
}
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));
}
Aggregations