Search in sources :

Example 51 with Headers

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();
}
Also used : Headers(okhttp3.Headers) Test(org.junit.Test)

Example 52 with Headers

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();
}
Also used : Header(retrofit2.http.Header) Request(okhttp3.Request) BigInteger(java.math.BigInteger) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 53 with Headers

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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HttpURLConnection(java.net.HttpURLConnection) OkHttpURLConnection(okhttp3.internal.huc.OkHttpURLConnection) Test(org.junit.Test)

Example 54 with Headers

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());
}
Also used : Response(okhttp3.Response) Headers(okhttp3.Headers) Request(okhttp3.Request) IOException(java.io.IOException)

Example 55 with Headers

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.");
    }
}
Also used : Response(okhttp3.Response) Headers(okhttp3.Headers) Request(okhttp3.Request) IOException(java.io.IOException)

Aggregations

Test (org.junit.Test)69 Request (okhttp3.Request)58 Response (okhttp3.Response)53 Headers (okhttp3.Headers)46 IOException (java.io.IOException)34 MockResponse (okhttp3.mockwebserver.MockResponse)33 HttpHeaders (okhttp3.internal.http.HttpHeaders)29 ResponseBody (okhttp3.ResponseBody)27 RequestBody (okhttp3.RequestBody)21 List (java.util.List)19 MediaType (okhttp3.MediaType)16 HashMap (java.util.HashMap)15 Map (java.util.Map)15 ANResponse (com.androidnetworking.common.ANResponse)13 AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)13 LinkedHashMap (java.util.LinkedHashMap)13 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)13 Buffer (okio.Buffer)12 ANError (com.androidnetworking.error.ANError)11 HttpURLConnection (java.net.HttpURLConnection)11