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));
}
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) {
}
}
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"));
}
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());
}
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));
}
Aggregations