use of okhttp3.Headers in project retrofit by square.
the class ResponseTest method successWithHeaders.
@Test
public void successWithHeaders() {
Object body = new Object();
Headers headers = Headers.of("foo", "bar");
Response<Object> response = Response.success(body, headers);
assertThat(response.raw()).isNotNull();
assertThat(response.code()).isEqualTo(200);
assertThat(response.message()).isEqualTo("OK");
assertThat(response.headers().toMultimap()).isEqualTo(headers.toMultimap());
assertThat(response.isSuccessful()).isTrue();
assertThat(response.body()).isSameAs(body);
assertThat(response.errorBody()).isNull();
}
use of okhttp3.Headers 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.Headers in project okhttp by square.
the class URLConnectionTest method noTransparentGzipFor304NotModified.
/**
* We had a bug where we attempted to gunzip responses that didn't have a body. This only came up
* with 304s since that response code can include headers (like "Content-Encoding") without any
* content to go along with it. https://github.com/square/okhttp/issues/358
*/
@Test
public void noTransparentGzipFor304NotModified() throws Exception {
server.enqueue(new MockResponse().clearHeaders().setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED).addHeader("Content-Encoding: gzip"));
server.enqueue(new MockResponse().setBody("b"));
HttpURLConnection connection1 = urlFactory.open(server.url("/").url());
assertEquals(HttpURLConnection.HTTP_NOT_MODIFIED, connection1.getResponseCode());
assertContent("", connection1);
HttpURLConnection connection2 = urlFactory.open(server.url("/").url());
assertEquals(HttpURLConnection.HTTP_OK, connection2.getResponseCode());
assertContent("b", connection2);
RecordedRequest requestA = server.takeRequest();
assertEquals(0, requestA.getSequenceNumber());
RecordedRequest requestB = server.takeRequest();
assertEquals(1, requestB.getSequenceNumber());
}
use of okhttp3.Headers in project realm-java by realm.
the class HttpUtils method stopSyncServer.
public static void stopSyncServer() throws Exception {
Request request = new Request.Builder().url(STOP_SERVER).build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful())
throw new IOException("Unexpected code " + response);
Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
RealmLog.debug(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
RealmLog.debug(response.body().string());
}
use of okhttp3.Headers in project realm-java by realm.
the class HttpUtils method startSyncServer.
public static void startSyncServer() throws Exception {
Request request = new Request.Builder().url(START_SERVER).build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful())
throw new IOException("Unexpected code " + response);
Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
RealmLog.debug(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
RealmLog.debug(response.body().string());
// FIXME: Server ready checking should be done in the control server side!
if (!waitAuthServerReady()) {
stopSyncServer();
throw new RuntimeException("Auth server cannot be started.");
}
}
Aggregations