Exemplo n.º 1
0
 @Test
 public void put() throws IOException {
   Request request = fromArgs("-X", "PUT", "-d", "foo", "http://example.com").createRequest();
   assertEquals("PUT", request.method());
   assertEquals("http://example.com/", request.url().toString());
   assertEquals(3, request.body().contentLength());
 }
Exemplo n.º 2
0
 @Test
 public void simple() {
   Request request = fromArgs("http://example.com").createRequest();
   assertEquals("GET", request.method());
   assertEquals("http://example.com/", request.url().toString());
   assertNull(request.body());
 }
Exemplo n.º 3
0
 @Test
 public void userAgent() {
   Request request = fromArgs("-A", "foo", "http://example.com").createRequest();
   assertEquals("GET", request.method());
   assertEquals("http://example.com/", request.url().toString());
   assertEquals("foo", request.header("User-Agent"));
   assertNull(request.body());
 }
Exemplo n.º 4
0
 @Test
 public void dataPut() {
   Request request = fromArgs("-d", "foo", "-X", "PUT", "http://example.com").createRequest();
   RequestBody body = request.body();
   assertEquals("PUT", request.method());
   assertEquals("http://example.com/", request.url().toString());
   assertEquals("application/x-www-form-urlencoded; charset=utf-8", body.contentType().toString());
   assertEquals("foo", bodyAsString(body));
 }
Exemplo n.º 5
0
 @Test
 public void contentTypeHeader() {
   Request request =
       fromArgs("-d", "foo", "-H", "Content-Type: application/json", "http://example.com")
           .createRequest();
   RequestBody body = request.body();
   assertEquals("POST", request.method());
   assertEquals("http://example.com/", request.url().toString());
   assertEquals("application/json; charset=utf-8", body.contentType().toString());
   assertEquals("foo", bodyAsString(body));
 }
 @Override
 public Response intercept(Interceptor.Chain chain) throws IOException {
   Request request = chain.request();
   request =
       (request
               .newBuilder()
               .header("X-Auth-Token", X_AUTH_TOKEN)
               .header("X-Response-Control", "minified"))
           .method(request.method(), request.body())
           .build();
   return chain.proceed(request);
 }
 @Override
 public Response intercept(Chain chain) throws IOException {
   Request original = chain.request();
   Request request =
       chain
           .request()
           .newBuilder()
           .headers(computeHeaders())
           .method(original.method(), original.body())
           .build();
   return chain.proceed(request);
 }