use of okhttp3.mockwebserver.RecordedRequest 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.mockwebserver.RecordedRequest in project okhttp by square.
the class CallTest method postBodyRetransmittedAfterAuthorizationFail.
private void postBodyRetransmittedAfterAuthorizationFail(String body) throws Exception {
server.enqueue(new MockResponse().setResponseCode(401));
server.enqueue(new MockResponse());
Request request = new Request.Builder().url(server.url("/")).method("POST", RequestBody.create(null, body)).build();
String credential = Credentials.basic("jesse", "secret");
client = client.newBuilder().authenticator(new RecordingOkAuthenticator(credential)).build();
Response response = client.newCall(request).execute();
assertEquals(200, response.code());
response.body().close();
RecordedRequest recordedRequest1 = server.takeRequest();
assertEquals("POST", recordedRequest1.getMethod());
assertEquals(body, recordedRequest1.getBody().readUtf8());
assertNull(recordedRequest1.getHeader("Authorization"));
RecordedRequest recordedRequest2 = server.takeRequest();
assertEquals("POST", recordedRequest2.getMethod());
assertEquals(body, recordedRequest2.getBody().readUtf8());
assertEquals(credential, recordedRequest2.getHeader("Authorization"));
}
use of okhttp3.mockwebserver.RecordedRequest in project okhttp by square.
the class CallTest method unspecifiedRequestBodyContentTypeDoesNotGetDefault.
@Test
public void unspecifiedRequestBodyContentTypeDoesNotGetDefault() throws Exception {
server.enqueue(new MockResponse());
Request request = new Request.Builder().url(server.url("/")).method("POST", RequestBody.create(null, "abc")).build();
executeSynchronously(request).assertCode(200);
RecordedRequest recordedRequest = server.takeRequest();
assertEquals(null, recordedRequest.getHeader("Content-Type"));
assertEquals("3", recordedRequest.getHeader("Content-Length"));
assertEquals("abc", recordedRequest.getBody().readUtf8());
}
use of okhttp3.mockwebserver.RecordedRequest in project okhttp by square.
the class CacheTest method etag.
@Test
public void etag() throws Exception {
RecordedRequest conditionalRequest = assertConditionallyCached(new MockResponse().addHeader("ETag: v1"));
assertEquals("v1", conditionalRequest.getHeader("If-None-Match"));
}
use of okhttp3.mockwebserver.RecordedRequest 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"));
}
Aggregations