use of okhttp3.RecordingCookieJar in project okhttp by square.
the class HttpOverHttp2Test method receiveResponseCookies.
@Test
public void receiveResponseCookies() throws Exception {
RecordingCookieJar cookieJar = new RecordingCookieJar();
client = client.newBuilder().cookieJar(cookieJar).build();
server.enqueue(new MockResponse().addHeader("set-cookie: a=b"));
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response = call.execute();
assertEquals("", response.body().string());
cookieJar.assertResponseCookies("a=b; path=/");
}
use of okhttp3.RecordingCookieJar in project okhttp by square.
the class HttpOverHttp2Test method sendRequestCookies.
@Test
public void sendRequestCookies() throws Exception {
RecordingCookieJar cookieJar = new RecordingCookieJar();
Cookie requestCookie = new Cookie.Builder().name("a").value("b").domain(server.getHostName()).build();
cookieJar.enqueueRequestCookies(requestCookie);
client = client.newBuilder().cookieJar(cookieJar).build();
server.enqueue(new MockResponse());
Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
Response response = call.execute();
assertEquals("", response.body().string());
RecordedRequest request = server.takeRequest();
assertEquals("a=b", request.getHeader("Cookie"));
}
use of okhttp3.RecordingCookieJar in project okhttp by square.
the class CallTest method responseCookies.
@Test
public void responseCookies() throws Exception {
server.enqueue(new MockResponse().addHeader("Set-Cookie", "a=b; Expires=Thu, 01 Jan 1970 00:00:00 GMT").addHeader("Set-Cookie", "c=d; Expires=Fri, 02 Jan 1970 23:59:59 GMT; path=/bar; secure"));
RecordingCookieJar cookieJar = new RecordingCookieJar();
client = client.newBuilder().cookieJar(cookieJar).build();
executeSynchronously("/").assertCode(200);
List<Cookie> responseCookies = cookieJar.takeResponseCookies();
assertEquals(2, responseCookies.size());
assertEquals("a=b; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/", responseCookies.get(0).toString());
assertEquals("c=d; expires=Fri, 02 Jan 1970 23:59:59 GMT; path=/bar; secure", responseCookies.get(1).toString());
}
use of okhttp3.RecordingCookieJar in project okhttp by square.
the class UrlConnectionCacheTest method cachePlusCookies.
@Test
public void cachePlusCookies() throws Exception {
RecordingCookieJar cookieJar = new RecordingCookieJar();
urlFactory.setClient(urlFactory.client().newBuilder().cookieJar(cookieJar).build());
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=FIRST").addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)).addHeader("Cache-Control: max-age=0").setBody("A"));
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=SECOND").setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
URL url = server.url("/").url();
assertEquals("A", readAscii(urlFactory.open(url)));
cookieJar.assertResponseCookies("a=FIRST; path=/");
assertEquals("A", readAscii(urlFactory.open(url)));
cookieJar.assertResponseCookies("a=SECOND; path=/");
}
use of okhttp3.RecordingCookieJar in project okhttp by square.
the class CacheTest method cachePlusCookies.
@Test
public void cachePlusCookies() throws Exception {
RecordingCookieJar cookieJar = new RecordingCookieJar();
client = client.newBuilder().cookieJar(cookieJar).build();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=FIRST").addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)).addHeader("Cache-Control: max-age=0").setBody("A"));
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=SECOND").setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
HttpUrl url = server.url("/");
assertEquals("A", get(url).body().string());
cookieJar.assertResponseCookies("a=FIRST; path=/");
assertEquals("A", get(url).body().string());
cookieJar.assertResponseCookies("a=SECOND; path=/");
}
Aggregations