private Builder(SimpleAsyncHttpClient client) { this.requestBuilder = new RequestBuilder(client.requestBuilder.build()); this.defaultThrowableHandler = client.defaultThrowableHandler; this.errorDocumentBehaviour = client.errorDocumentBehaviour; this.enableResumableDownload = client.resumeEnabled; this.ahc = client.getAsyncHttpClient(); this.listener = client.listener; }
public Future<Response> delete() throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("DELETE"); return execute(r, null, null); }
public Future<Response> delete(BodyConsumer bodyConsumer) throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("DELETE"); return execute(r, bodyConsumer, null); }
public Future<Response> head(ThrowableHandler throwableHandler) throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("HEAD"); return execute(r, null, throwableHandler); }
public Future<Response> head() throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("HEAD"); return execute(r, null, null); }
public Future<Response> options(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("OPTIONS"); return execute(r, bodyConsumer, throwableHandler); }
public Future<Response> options() throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("OPTIONS"); return execute(r, null, null); }
public Future<Response> post(BodyConsumer consumer, Part... parts) throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("POST"); for (Part part : parts) { r.addBodyPart(part); } return execute(r, consumer, null); }
public Future<Response> post(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer) throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("POST"); r.setBody(bodyGenerator); return execute(r, bodyConsumer, null); }
public Future<Response> put(Part... parts) throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("POST"); for (Part part : parts) { r.addBodyPart(part); } return execute(r, null, null); }
public Future<Response> put(BodyConsumer consumer, Part... parts) throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("POST"); for (Part part : parts) { r.addBodyPart(part); } return execute(r, consumer, null); }
public Future<Response> post(BodyGenerator bodyGenerator) throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("POST"); r.setBody(bodyGenerator); return execute(r, null, null); }
public Future<Response> post(BodyGenerator bodyGenerator, ThrowableHandler throwableHandler) throws IOException { RequestBuilder r = rebuildRequest(requestBuilder.build()); r.setMethod("POST"); r.setBody(bodyGenerator); return execute(r, null, throwableHandler); }
@Test public void testPercentageEncodedUserInfo() { final Request req = get("http://hello:wor%20ld@foo.com").build(); assertEquals(req.getMethod(), "GET"); assertEquals(req.getUrl(), "http://hello:wor%20ld@foo.com"); }
@Test public void testParsesQueryParams() { Request request = get("http://foo.com/?param1=value1").addQueryParam("param2", "value2").build(); assertEquals(request.getUrl(), "http://foo.com/?param1=value1¶m2=value2"); List<Param> params = request.getQueryParams(); assertEquals(params.size(), 2); assertEquals(params.get(0), new Param("param1", "value1")); assertEquals(params.get(1), new Param("param2", "value2")); }
@Test public void testContentTypeCharsetToBodyEncoding() { final Request req = get("http://localhost").setHeader("Content-Type", "application/json; charset=utf-8").build(); assertEquals(req.getCharset(), UTF_8); final Request req2 = get("http://localhost").setHeader("Content-Type", "application/json; charset=\"utf-8\"").build(); assertEquals(req2.getCharset(), UTF_8); }
@Test public void testUserProvidedRequestMethod() { Request req = new RequestBuilder("ABC").setUrl("http://foo.com").build(); assertEquals(req.getMethod(), "ABC"); assertEquals(req.getUrl(), "http://foo.com"); }
@Test public void testSignatureBaseStringWithProperlyEncodedUri() throws NoSuchAlgorithmException { Request request = post("http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b") .addFormParam("c2", "") .addFormParam("a3", "2 q") .build(); testSignatureBaseString(request); testSignatureBaseStringWithEncodableOAuthToken(request); }
@Test public void mkcolWebDavTest1() throws InterruptedException, IOException, ExecutionException { try (AsyncHttpClient c = asyncHttpClient()) { Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build(); Response response = c.executeRequest(mkcolRequest).get(); assertEquals(response.getStatusCode(), 201); } }
@Test public void basicPropFindWebDavTest() throws InterruptedException, IOException, ExecutionException { try (AsyncHttpClient c = asyncHttpClient()) { Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(getTargetUrl()).build(); Response response = c.executeRequest(propFindRequest).get(); assertEquals(response.getStatusCode(), 404); } }