Search in sources :

Example 1 with HeaderMap

use of retrofit2.http.HeaderMap in project retrofit by square.

the class RequestBuilderTest method getWithHeaderMap.

@Test
public void getWithHeaderMap() {
    class Example {

        @GET("/search")
        Call<ResponseBody> method(@HeaderMap Map<String, Object> headers) {
            return null;
        }
    }
    Map<String, Object> headers = new LinkedHashMap<>();
    headers.put("Accept", "text/plain");
    headers.put("Accept-Charset", "utf-8");
    Request request = buildRequest(Example.class, headers);
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.url().toString()).isEqualTo("http://example.com/search");
    assertThat(request.body()).isNull();
    assertThat(request.headers().size()).isEqualTo(2);
    assertThat(request.header("Accept")).isEqualTo("text/plain");
    assertThat(request.header("Accept-Charset")).isEqualTo("utf-8");
}
Also used : HeaderMap(retrofit2.http.HeaderMap) Request(okhttp3.Request) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with HeaderMap

use of retrofit2.http.HeaderMap in project retrofit by square.

the class RequestBuilderTest method headerMapSupportsSubclasses.

@Test
public void headerMapSupportsSubclasses() {
    class Foo extends HashMap<String, String> {
    }
    class Example {

        @GET("/search")
        Call<ResponseBody> method(@HeaderMap Foo headers) {
            return null;
        }
    }
    Foo headers = new Foo();
    headers.put("Accept", "text/plain");
    Request request = buildRequest(Example.class, headers);
    assertThat(request.url().toString()).isEqualTo("http://example.com/search");
    assertThat(request.headers().size()).isEqualTo(1);
    assertThat(request.header("Accept")).isEqualTo("text/plain");
}
Also used : HeaderMap(retrofit2.http.HeaderMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Request (okhttp3.Request)2 ResponseBody (okhttp3.ResponseBody)2 Test (org.junit.Test)2 HeaderMap (retrofit2.http.HeaderMap)2 Map (java.util.Map)1 FieldMap (retrofit2.http.FieldMap)1 PartMap (retrofit2.http.PartMap)1 QueryMap (retrofit2.http.QueryMap)1