use of okhttp3.internal.http2.Header in project retrofit by square.
the class RequestBuilderTest method malformedContentTypeParameterThrows.
@Test
public void malformedContentTypeParameterThrows() {
class Example {
//
@POST("/")
Call<ResponseBody> method(@Header("Content-Type") String contentType, @Body RequestBody body) {
return null;
}
}
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
try {
buildRequest(Example.class, "hello, world!", body);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Malformed content type: hello, world!");
}
}
use of okhttp3.internal.http2.Header in project retrofit by square.
the class RequestBuilderTest method headerParamToString.
@Test
public void headerParamToString() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@Header("kit") BigInteger kit) {
return null;
}
}
Request request = buildRequest(Example.class, new BigInteger("1234"));
assertThat(request.method()).isEqualTo("GET");
okhttp3.Headers headers = request.headers();
assertThat(headers.size()).isEqualTo(1);
assertThat(headers.get("kit")).isEqualTo("1234");
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class URLConnectionTest method connectionCloseInRequest.
@Test
public void connectionCloseInRequest() throws IOException, InterruptedException {
// server doesn't honor the connection: close header!
server.enqueue(new MockResponse());
server.enqueue(new MockResponse());
HttpURLConnection a = urlFactory.open(server.url("/").url());
a.setRequestProperty("Connection", "close");
assertEquals(200, a.getResponseCode());
HttpURLConnection b = urlFactory.open(server.url("/").url());
assertEquals(200, b.getResponseCode());
assertEquals(0, server.takeRequest().getSequenceNumber());
assertEquals("When connection: close is used, each request should get its own connection", 0, server.takeRequest().getSequenceNumber());
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class URLConnectionTest method authenticateWithGetAndTransparentGzip.
/** https://code.google.com/p/android/issues/detail?id=74026 */
@Test
public void authenticateWithGetAndTransparentGzip() throws Exception {
MockResponse pleaseAuthenticate = new MockResponse().setResponseCode(401).addHeader("WWW-Authenticate: Basic realm=\"protected area\"").setBody("Please authenticate.");
// fail auth three times...
server.enqueue(pleaseAuthenticate);
server.enqueue(pleaseAuthenticate);
server.enqueue(pleaseAuthenticate);
// ...then succeed the fourth time
MockResponse successfulResponse = new MockResponse().addHeader("Content-Encoding", "gzip").setBody(gzip("Successful auth!"));
server.enqueue(successfulResponse);
Authenticator.setDefault(new RecordingAuthenticator());
urlFactory.setClient(urlFactory.client().newBuilder().authenticator(new JavaNetAuthenticator()).build());
connection = urlFactory.open(server.url("/").url());
assertEquals("Successful auth!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
// no authorization header for the first request...
RecordedRequest request = server.takeRequest();
assertNull(request.getHeader("Authorization"));
// ...but the three requests that follow requests include an authorization header
for (int i = 0; i < 3; i++) {
request = server.takeRequest();
assertEquals("GET / HTTP/1.1", request.getRequestLine());
assertEquals("Basic " + RecordingAuthenticator.BASE_64_CREDENTIALS, request.getHeader("Authorization"));
}
}
use of okhttp3.internal.http2.Header in project okhttp by square.
the class URLConnectionTest method testAuthenticateWithStreamingPost.
private void testAuthenticateWithStreamingPost(StreamingMode streamingMode) throws Exception {
MockResponse pleaseAuthenticate = new MockResponse().setResponseCode(401).addHeader("WWW-Authenticate: Basic realm=\"protected area\"").setBody("Please authenticate.");
server.enqueue(pleaseAuthenticate);
Authenticator.setDefault(new RecordingAuthenticator());
urlFactory.setClient(urlFactory.client().newBuilder().authenticator(new JavaNetAuthenticator()).build());
connection = urlFactory.open(server.url("/").url());
connection.setDoOutput(true);
byte[] requestBody = { 'A', 'B', 'C', 'D' };
if (streamingMode == StreamingMode.FIXED_LENGTH) {
connection.setFixedLengthStreamingMode(requestBody.length);
} else if (streamingMode == StreamingMode.CHUNKED) {
connection.setChunkedStreamingMode(0);
}
OutputStream outputStream = connection.getOutputStream();
outputStream.write(requestBody);
outputStream.close();
try {
connection.getInputStream();
fail();
} catch (HttpRetryException expected) {
}
// no authorization header for the request...
RecordedRequest request = server.takeRequest();
assertNull(request.getHeader("Authorization"));
assertEquals("ABCD", request.getBody().readUtf8());
}
Aggregations