use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method varyMatchesChangedRequestHeaderField.
@Test
public void varyMatchesChangedRequestHeaderField() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").addHeader("Vary: Accept-Language").setBody("A"));
server.enqueue(new MockResponse().setBody("B"));
HttpUrl url = server.url("/");
Request frRequest = new Request.Builder().url(url).header("Accept-Language", "fr-CA").build();
Response frResponse = client.newCall(frRequest).execute();
assertEquals("A", frResponse.body().string());
Request enRequest = new Request.Builder().url(url).header("Accept-Language", "en-US").build();
Response enResponse = client.newCall(enRequest).execute();
assertEquals("B", enResponse.body().string());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method varyFieldsAreCaseInsensitive.
@Test
public void varyFieldsAreCaseInsensitive() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").addHeader("Vary: ACCEPT-LANGUAGE").setBody("A"));
server.enqueue(new MockResponse().setBody("B"));
HttpUrl url = server.url("/");
Request request = new Request.Builder().url(url).header("Accept-Language", "fr-CA").build();
Response response1 = client.newCall(request).execute();
assertEquals("A", response1.body().string());
Request request1 = new Request.Builder().url(url).header("accept-language", "fr-CA").build();
Response response2 = client.newCall(request1).execute();
assertEquals("A", response2.body().string());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method combinedCacheHeadersCanBeNonAscii.
@Test
public void combinedCacheHeadersCanBeNonAscii() throws Exception {
server.enqueue(new MockResponse().addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)).addHeader("Cache-Control: max-age=0").addHeaderLenient("Alpha", "α").addHeaderLenient("β", "Beta").setBody("abcd"));
server.enqueue(new MockResponse().addHeader("Transfer-Encoding: none").addHeaderLenient("Gamma", "Γ").addHeaderLenient("Δ", "Delta").setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
Response response1 = get(server.url("/"));
assertEquals("α", response1.header("Alpha"));
assertEquals("Beta", response1.header("β"));
assertEquals("abcd", response1.body().string());
Response response2 = get(server.url("/"));
assertEquals("α", response2.header("Alpha"));
assertEquals("Beta", response2.header("β"));
assertEquals("Γ", response2.header("Gamma"));
assertEquals("Delta", response2.header("Δ"));
assertEquals("abcd", response2.body().string());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method requestMaxStale.
@Test
public void requestMaxStale() throws IOException {
server.enqueue(new MockResponse().setBody("A").addHeader("Cache-Control: max-age=120").addHeader("Date: " + formatDate(-4, TimeUnit.MINUTES)));
server.enqueue(new MockResponse().setBody("B"));
assertEquals("A", get(server.url("/")).body().string());
Request request = new Request.Builder().url(server.url("/")).header("Cache-Control", "max-stale=180").build();
Response response = client.newCall(request).execute();
assertEquals("A", response.body().string());
assertEquals("110 HttpURLConnection \"Response is stale\"", response.header("Warning"));
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method varyMultipleFieldsWithMatch.
@Test
public void varyMultipleFieldsWithMatch() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").addHeader("Vary: Accept-Language, Accept-Charset").addHeader("Vary: Accept-Encoding").setBody("A"));
server.enqueue(new MockResponse().setBody("B"));
HttpUrl url = server.url("/");
Request request = new Request.Builder().url(url).header("Accept-Language", "fr-CA").header("Accept-Charset", "UTF-8").header("Accept-Encoding", "identity").build();
Response response1 = client.newCall(request).execute();
assertEquals("A", response1.body().string());
Request request1 = new Request.Builder().url(url).header("Accept-Language", "fr-CA").header("Accept-Charset", "UTF-8").header("Accept-Encoding", "identity").build();
Response response2 = client.newCall(request1).execute();
assertEquals("A", response2.body().string());
}
Aggregations