use of okhttp3.internal.http2.Header in project Fast-Android-Networking by amitshekhariitbhu.
the class GzipRequestInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) {
return chain.proceed(originalRequest);
}
Request compressedRequest = originalRequest.newBuilder().header("Content-Encoding", "gzip").method(originalRequest.method(), forceContentLength(gzip(originalRequest.body()))).build();
return chain.proceed(compressedRequest);
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method requestOnlyIfCachedWithNoResponseCached.
@Test
public void requestOnlyIfCachedWithNoResponseCached() throws IOException {
// (no responses enqueued)
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(1, cache.requestCount());
assertEquals(0, cache.networkCount());
assertEquals(0, cache.hitCount());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class OkApacheClientTest method jsonGzipResponse.
@Test
public void jsonGzipResponse() throws Exception {
String text = "{\"Message\": { \"text\": \"Hello, World!\" } }";
server.enqueue(new MockResponse().setBody(gzip(text)).setHeader("Content-Encoding", "gzip").setHeader("Content-Type", "application/json"));
HttpGet request1 = new HttpGet(server.url("/").url().toURI());
// Not transparent gzip.
request1.setHeader("Accept-encoding", "gzip");
HttpResponse response = client.execute(request1);
HttpEntity entity = response.getEntity();
Header[] encodingHeaders = response.getHeaders("Content-Encoding");
assertEquals(1, encodingHeaders.length);
assertEquals("gzip", encodingHeaders[0].getValue());
assertNotNull(entity.getContentEncoding());
assertEquals("gzip", entity.getContentEncoding().getValue());
Header[] typeHeaders = response.getHeaders("Content-Type");
assertEquals(1, typeHeaders.length);
assertEquals("application/json", typeHeaders[0].getValue());
assertNotNull(entity.getContentType());
assertEquals("application/json", entity.getContentType().getValue());
assertEquals(text, gunzip(entity));
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class OkApacheClientTest method contentType.
@Test
public void contentType() throws Exception {
server.enqueue(new MockResponse().setBody("<html><body><h1>Hello, World!</h1></body></html>").setHeader("Content-Type", "text/html"));
server.enqueue(new MockResponse().setBody("{\"Message\": { \"text\": \"Hello, World!\" } }").setHeader("Content-Type", "application/json"));
server.enqueue(new MockResponse().setBody("Hello, World!"));
HttpGet request1 = new HttpGet(server.url("/").url().toURI());
HttpResponse response1 = client.execute(request1);
Header[] headers1 = response1.getHeaders("Content-Type");
assertEquals(1, headers1.length);
assertEquals("text/html", headers1[0].getValue());
assertNotNull(response1.getEntity().getContentType());
assertEquals("text/html", response1.getEntity().getContentType().getValue());
HttpGet request2 = new HttpGet(server.url("/").url().toURI());
HttpResponse response2 = client.execute(request2);
Header[] headers2 = response2.getHeaders("Content-Type");
assertEquals(1, headers2.length);
assertEquals("application/json", headers2[0].getValue());
assertNotNull(response2.getEntity().getContentType());
assertEquals("application/json", response2.getEntity().getContentType().getValue());
HttpGet request3 = new HttpGet(server.url("/").url().toURI());
HttpResponse response3 = client.execute(request3);
Header[] headers3 = response3.getHeaders("Content-Type");
assertEquals(0, headers3.length);
assertNull(response3.getEntity().getContentType());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class Case method getHeaders.
public List<Header> getHeaders() {
List<Header> result = new ArrayList<>();
for (Map<String, String> inputHeader : headers) {
Map.Entry<String, String> entry = inputHeader.entrySet().iterator().next();
result.add(new Header(entry.getKey(), entry.getValue()));
}
return result;
}
Aggregations