Search in sources :

Example 36 with Headers

use of okhttp3.Headers in project okhttp by square.

the class HeadersTest method ofMapMakesDefensiveCopy.

@Test
public void ofMapMakesDefensiveCopy() {
    Map<String, String> namesAndValues = new LinkedHashMap<>();
    namesAndValues.put("User-Agent", "OkHttp");
    Headers headers = Headers.of(namesAndValues);
    namesAndValues.put("User-Agent", "Chrome");
    assertEquals("OkHttp", headers.value(0));
}
Also used : HttpHeaders(okhttp3.internal.http.HttpHeaders) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 37 with Headers

use of okhttp3.Headers in project okhttp by square.

the class HeadersTest method nameIndexesAreStrict.

@Test
public void nameIndexesAreStrict() {
    Headers headers = Headers.of("a", "b", "c", "d");
    try {
        headers.name(-1);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
    assertEquals("a", headers.name(0));
    assertEquals("c", headers.name(1));
    try {
        headers.name(2);
        fail();
    } catch (IndexOutOfBoundsException expected) {
    }
}
Also used : HttpHeaders(okhttp3.internal.http.HttpHeaders) Test(org.junit.Test)

Example 38 with Headers

use of okhttp3.Headers in project okhttp by square.

the class HeadersTest method addParsing.

@Test
public void addParsing() {
    Headers headers = new Headers.Builder().add("foo: bar").add(// Name leading whitespace is trimmed.
    " foo: baz").add(// Name trailing whitespace is trimmed.
    "foo : bak").add(// '\t' also counts as whitespace
    "\tkey\t:\tvalue\t").add(// Value whitespace is trimmed.
    "ping:  pong  ").add(// Space after colon is not required.
    "kit:kat").build();
    assertEquals(Arrays.asList("bar", "baz", "bak"), headers.values("foo"));
    assertEquals(Arrays.asList("value"), headers.values("key"));
    assertEquals(Arrays.asList("pong"), headers.values("ping"));
    assertEquals(Arrays.asList("kat"), headers.values("kit"));
}
Also used : HttpHeaders(okhttp3.internal.http.HttpHeaders) Test(org.junit.Test)

Example 39 with Headers

use of okhttp3.Headers in project okhttp by square.

the class HeadersTest method headersToString.

@Test
public void headersToString() {
    Headers headers = new Headers.Builder().add("A", "a").add("B", "bb").build();
    assertEquals("A: a\nB: bb\n", headers.toString());
}
Also used : HttpHeaders(okhttp3.internal.http.HttpHeaders) Test(org.junit.Test)

Example 40 with Headers

use of okhttp3.Headers in project okhttp by square.

the class HeadersTest method ofMapTrimsKey.

@Test
public void ofMapTrimsKey() {
    Headers headers = Headers.of(Collections.singletonMap(" User-Agent ", "OkHttp"));
    assertEquals("User-Agent", headers.name(0));
}
Also used : HttpHeaders(okhttp3.internal.http.HttpHeaders) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)69 Request (okhttp3.Request)55 Response (okhttp3.Response)50 Headers (okhttp3.Headers)43 MockResponse (okhttp3.mockwebserver.MockResponse)33 IOException (java.io.IOException)32 HttpHeaders (okhttp3.internal.http.HttpHeaders)27 ResponseBody (okhttp3.ResponseBody)25 List (java.util.List)19 RequestBody (okhttp3.RequestBody)19 HashMap (java.util.HashMap)14 Map (java.util.Map)14 ANResponse (com.androidnetworking.common.ANResponse)13 AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)13 LinkedHashMap (java.util.LinkedHashMap)13 MediaType (okhttp3.MediaType)13 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)13 ANError (com.androidnetworking.error.ANError)11 HttpURLConnection (java.net.HttpURLConnection)11 JSONObject (org.json.JSONObject)11