/** * Create a new POST request builder. The client name will be selected based * on a prefix of the host name. * * @param uri * URI to use for the request. * @return * Builder for creating and executing a request. */ default HttpRequestBuilder post(URI uri) { return newRequest(HttpUtils.clientNameForURI(uri), uri).withMethod("POST"); }
private int getHeadersLength(List<Header> headers) { int size = 0; for (Header h : headers) { size += h.numBytes(); } return size; }
@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()); }
/** Return the overall latency for a group of requests including all retries. */ public long getOverallLatency() { if (maxAttempts <= 1 || originalStart < 0) { return getLatency(); } else if (events.isEmpty()) { return -1; } else { return events.get(events.size() - 1).timestamp() - originalStart; } }
/** Set the request method (GET, PUT, POST, DELETE). */ public HttpRequestBuilder withMethod(String m) { this.method = m; entry.withMethod(method); return this; }
/** Sets the policy used to verify hostnames when using HTTPS. */ public HttpRequestBuilder withHostnameVerifier(HostnameVerifier verifier) { requireHttps("hostname verification cannot be used with http, switch to https"); this.hostVerifier = verifier; return this; }
/** * Create a new PUT request builder. The client name will be selected based * on a prefix of the host name. * * @param uri * URI to use for the request. * @return * Builder for creating and executing a request. */ default HttpRequestBuilder put(URI uri) { return newRequest(HttpUtils.clientNameForURI(uri), uri).withMethod("PUT"); }
/** Sets the socket factory to use with HTTPS. */ public HttpRequestBuilder withSSLSocketFactory(SSLSocketFactory factory) { requireHttps("ssl cannot be used with http, use https"); this.sslFactory = factory; return this; }
/** * Create a new GET request builder. The client name will be selected based * on a prefix of the host name. * * @param uri * URI to use for the request. * @return * Builder for creating and executing a request. */ default HttpRequestBuilder get(URI uri) { return newRequest(HttpUtils.clientNameForURI(uri), uri).withMethod("GET"); }
/** * Create a new DELETE request builder. The client name will be selected based * on a prefix of the host name. * * @param uri * URI to use for the request. * @return * Builder for creating and executing a request. */ default HttpRequestBuilder delete(URI uri) { return newRequest(HttpUtils.clientNameForURI(uri), uri).withMethod("DELETE"); } }
/** * Create a new POST request builder. The client name will be selected based * on a prefix of the host name. * * @param uri * URI to use for the request. * @return * Builder for creating and executing a request. */ default HttpRequestBuilder post(URI uri) { return newRequest(HttpUtils.clientNameForURI(uri), uri).withMethod("POST"); }
/** * Create a new GET request builder. The client name will be selected based * on a prefix of the host name. * * @param uri * URI to use for the request. * @return * Builder for creating and executing a request. */ default HttpRequestBuilder get(URI uri) { return newRequest(HttpUtils.clientNameForURI(uri), uri).withMethod("GET"); }
/** * Create a new PUT request builder. The client name will be selected based * on a prefix of the host name. * * @param uri * URI to use for the request. * @return * Builder for creating and executing a request. */ default HttpRequestBuilder put(URI uri) { return newRequest(HttpUtils.clientNameForURI(uri), uri).withMethod("PUT"); }
/** * Create a new DELETE request builder. The client name will be selected based * on a prefix of the host name. * * @param uri * URI to use for the request. * @return * Builder for creating and executing a request. */ default HttpRequestBuilder delete(URI uri) { return newRequest(HttpUtils.clientNameForURI(uri), uri).withMethod("DELETE"); } }