use of okhttp3.internal.http2.Header in project okhttp by square.
the class CallTest method expect100ContinueTimesOutWithoutContinue.
@Test
public void expect100ContinueTimesOutWithoutContinue() throws Exception {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE));
client = client.newBuilder().readTimeout(500, TimeUnit.MILLISECONDS).build();
Request request = new Request.Builder().url(server.url("/")).header("Expect", "100-continue").post(RequestBody.create(MediaType.parse("text/plain"), "abc")).build();
Call call = client.newCall(request);
try {
call.execute();
fail();
} catch (SocketTimeoutException expected) {
}
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("", recordedRequest.getBody().readUtf8());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method varyMatchesRemovedRequestHeaderField.
@Test
public void varyMatchesRemovedRequestHeaderField() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").addHeader("Vary: Foo").setBody("A"));
server.enqueue(new MockResponse().setBody("B"));
Request request = new Request.Builder().url(server.url("/")).header("Foo", "bar").build();
Response fooresponse = client.newCall(request).execute();
assertEquals("A", fooresponse.body().string());
assertEquals("B", get(server.url("/")).body().string());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method conditionalHitUpdatesCache.
@Test
public void conditionalHitUpdatesCache() throws Exception {
server.enqueue(new MockResponse().addHeader("Last-Modified: " + formatDate(0, TimeUnit.SECONDS)).addHeader("Cache-Control: max-age=0").setBody("A"));
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=30").addHeader("Allow: GET, HEAD").setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
server.enqueue(new MockResponse().setBody("B"));
// A cache miss writes the cache.
long t0 = System.currentTimeMillis();
Response response1 = get(server.url("/a"));
assertEquals("A", response1.body().string());
assertEquals(null, response1.header("Allow"));
assertEquals(0, response1.receivedResponseAtMillis() - t0, 250.0);
// A conditional cache hit updates the cache.
// Make sure t0 and t1 are distinct.
Thread.sleep(500);
long t1 = System.currentTimeMillis();
Response response2 = get(server.url("/a"));
assertEquals(HttpURLConnection.HTTP_OK, response2.code());
assertEquals("A", response2.body().string());
assertEquals("GET, HEAD", response2.header("Allow"));
assertEquals(0, response2.receivedResponseAtMillis() - t1, 250.0);
// A full cache hit reads the cache.
// Make sure t1 and t2 are distinct.
Thread.sleep(500);
long t2 = System.currentTimeMillis();
Response response3 = get(server.url("/a"));
assertEquals("A", response3.body().string());
assertEquals("GET, HEAD", response3.header("Allow"));
assertEquals(0, response3.receivedResponseAtMillis() - t1, 250.0);
assertEquals(2, server.getRequestCount());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method requestMaxAge.
@Test
public void requestMaxAge() throws IOException {
server.enqueue(new MockResponse().setBody("A").addHeader("Last-Modified: " + formatDate(-2, TimeUnit.HOURS)).addHeader("Date: " + formatDate(-1, TimeUnit.MINUTES)).addHeader("Expires: " + formatDate(1, TimeUnit.HOURS)));
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-age=30").build();
Response response = client.newCall(request).execute();
assertEquals("B", response.body().string());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method requestOnlyIfCachedWithUnhelpfulResponseCached.
@Test
public void requestOnlyIfCachedWithUnhelpfulResponseCached() throws IOException {
server.enqueue(new MockResponse().setBody("A"));
assertEquals("A", get(server.url("/")).body().string());
Request request = new Request.Builder().url(server.url("/")).header("Cache-Control", "only-if-cached").build();
Response response = client.newCall(request).execute();
assertTrue(response.body().source().exhausted());
assertEquals(504, response.code());
assertEquals(2, cache.requestCount());
assertEquals(1, cache.networkCount());
assertEquals(0, cache.hitCount());
}
Aggregations