/** Add header to accept {@code application/json} data. */ public HttpRequestBuilder acceptJson() { return addHeader("Accept", "application/json"); }
/** Set the request body. */ public HttpRequestBuilder withContent(String type, byte[] content) { addHeader("Content-Type", type); entity = content; return this; }
/** Add user-agent header. */ public HttpRequestBuilder userAgent(String agent) { return addHeader("User-Agent", agent); }
/** Set the request body. */ public HttpRequestBuilder withContent(String type, byte[] content) { addHeader("Content-Type", type); entity = content; return this; }
/** Add accept-encoding header. */ public HttpRequestBuilder acceptEncoding(String enc) { return addHeader("Accept-Encoding", enc); }
/** Add header to accept {@code application/json} data. */ public HttpRequestBuilder acceptJson() { return addHeader("Accept", "application/json"); }
/** Add user-agent header. */ public HttpRequestBuilder userAgent(String agent) { return addHeader("User-Agent", agent); }
/** Add accept header. */ public HttpRequestBuilder accept(String type) { return addHeader("Accept", type); }
/** Add accept header. */ public HttpRequestBuilder accept(String type) { return addHeader("Accept", type); }
/** Add accept-encoding header. */ public HttpRequestBuilder acceptEncoding(String enc) { return addHeader("Accept-Encoding", enc); }
/** * Compress the request body using the specified compression level. * The content must have already been set on the builder. */ public HttpRequestBuilder compress(int level) throws IOException { addHeader("Content-Encoding", "gzip"); entity = HttpUtils.gzip(entity, level); return this; }
/** * Compress the request body using the specified compression level. * The content must have already been set on the builder. */ public HttpRequestBuilder compress(int level) throws IOException { addHeader("Content-Encoding", "gzip"); entity = HttpUtils.gzip(entity, level); return this; }
@Test public void okWithBody() throws IOException { HttpResponse res = HttpClient.DEFAULT .post(uri("/echo")) .addHeader("X-Status", "200") .withContent("text/plain", "foo") .send(); Assertions.assertEquals(200, res.status()); Assertions.assertEquals("foo", res.entityAsString()); }
@Test public void okWithCompressedBody() throws IOException { HttpResponse res = HttpClient.DEFAULT .post(uri("/echo")) .acceptGzip() .addHeader("X-Status", "200") .withContent("text/plain", "foo") .compress() .send() .decompress(); Assertions.assertEquals(200, res.status()); Assertions.assertEquals("foo", res.entityAsString()); } }