use of okhttp3.internal.http2.Header in project okhttp by square.
the class CacheTest method varyMultipleFieldsWithNoMatch.
@Test
public void varyMultipleFieldsWithNoMatch() 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 frRequest = new Request.Builder().url(url).header("Accept-Language", "fr-CA").header("Accept-Charset", "UTF-8").header("Accept-Encoding", "identity").build();
Response frResponse = client.newCall(frRequest).execute();
assertEquals("A", frResponse.body().string());
Request enRequest = new Request.Builder().url(url).header("Accept-Language", "en-CA").header("Accept-Charset", "UTF-8").header("Accept-Encoding", "identity").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 authorizationRequestFullyCached.
@Test
public void authorizationRequestFullyCached() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").setBody("A"));
server.enqueue(new MockResponse().setBody("B"));
HttpUrl url = server.url("/");
Request request = new Request.Builder().url(url).header("Authorization", "password").build();
Response response = client.newCall(request).execute();
assertEquals("A", response.body().string());
assertEquals("A", get(url).body().string());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CallTest method httpsWithIpAddress.
@Test
public void httpsWithIpAddress() throws Exception {
String localIpAddress = InetAddress.getLoopbackAddress().getHostAddress();
// Create a certificate with an IP address in the subject alt name.
HeldCertificate heldCertificate = new HeldCertificate.Builder().commonName("example.com").subjectAlternativeName(localIpAddress).build();
SslClient sslClient = new SslClient.Builder().certificateChain(heldCertificate.keyPair, heldCertificate.certificate).addTrustedCertificate(heldCertificate.certificate).build();
// Use that certificate on the server and trust it on the client.
server.useHttps(sslClient.socketFactory, false);
client = client.newBuilder().sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).hostnameVerifier(new RecordingHostnameVerifier()).protocols(Collections.singletonList(Protocol.HTTP_1_1)).build();
// Make a request.
server.enqueue(new MockResponse());
HttpUrl url = server.url("/").newBuilder().host(localIpAddress).build();
Request request = new Request.Builder().url(url).build();
executeSynchronously(request).assertCode(200);
// Confirm that the IP address was used in the host header.
RecordedRequest recordedRequest = server.takeRequest();
assertEquals(localIpAddress + ":" + server.getPort(), recordedRequest.getHeader("Host"));
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class CallTest method illegalToExecuteTwice.
@Test
public void illegalToExecuteTwice() throws Exception {
server.enqueue(new MockResponse().setBody("abc").addHeader("Content-Type: text/plain"));
Request request = new Request.Builder().url(server.url("/")).header("User-Agent", "SyncApiTest").build();
Call call = client.newCall(request);
Response response = call.execute();
response.body().close();
try {
call.execute();
fail();
} catch (IllegalStateException e) {
assertEquals("Already Executed", e.getMessage());
}
try {
call.enqueue(callback);
fail();
} catch (IllegalStateException e) {
assertEquals("Already Executed", e.getMessage());
}
assertEquals("SyncApiTest", server.takeRequest().getHeader("User-Agent"));
}
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());
}
Aggregations