/** Returns the {@link HttpRequest} that has been setup by this builder so far. After using the request, it should be returned * to the pool via {@code Pools.free(request)}. */ public HttpRequest build () { validate(); HttpRequest request = httpRequest; httpRequest = null; return request; }
/** Returns the {@link HttpRequest} that has been setup by this builder so far. After using the request, it should be returned * to the pool via {@code Pools.free(request)}. */ public HttpRequest build () { validate(); HttpRequest request = httpRequest; httpRequest = null; return request; }
/** The {@link #baseUrl} will automatically be added as a prefix to the given URL. * * @see HttpRequest#setUrl(String) */ public HttpRequestBuilder url (String url) { validate(); httpRequest.setUrl(baseUrl + url); return this; }
/** @see HttpRequest#setHeader(String, String) */ public HttpRequestBuilder header (String name, String value) { validate(); httpRequest.setHeader(name, value); return this; }
/** @see HttpRequest#setFollowRedirects(boolean) */ public HttpRequestBuilder followRedirects (boolean followRedirects) { validate(); httpRequest.setFollowRedirects(followRedirects); return this; }
/** @see HttpRequest#setContent(String) */ public HttpRequestBuilder content (String content) { validate(); httpRequest.setContent(content); return this; }
/** @see HttpRequest#setMethod(String) */ public HttpRequestBuilder method (String httpMethod) { validate(); httpRequest.setMethod(httpMethod); return this; }
/** @see HttpRequest#setContent(String) */ public HttpRequestBuilder content (String content) { validate(); httpRequest.setContent(content); return this; }
/** @see HttpRequest#setMethod(String) */ public HttpRequestBuilder method (String httpMethod) { validate(); httpRequest.setMethod(httpMethod); return this; }
/** @see HttpRequest#setContent(java.io.InputStream, long) */ public HttpRequestBuilder content (InputStream contentStream, long contentLength) { validate(); httpRequest.setContent(contentStream, contentLength); return this; }
/** @see HttpRequest#setFollowRedirects(boolean) */ public HttpRequestBuilder followRedirects (boolean followRedirects) { validate(); httpRequest.setFollowRedirects(followRedirects); return this; }
/** @see HttpRequest#setContent(java.io.InputStream, long) */ public HttpRequestBuilder content (InputStream contentStream, long contentLength) { validate(); httpRequest.setContent(contentStream, contentLength); return this; }
/** The {@link #baseUrl} will automatically be added as a prefix to the given URL. * * @see HttpRequest#setUrl(String) */ public HttpRequestBuilder url (String url) { validate(); httpRequest.setUrl(baseUrl + url); return this; }
/** If this method is not called, the {@link #defaultTimeout} will be used. * * @see HttpRequest#setTimeOut(int) */ public HttpRequestBuilder timeout (int timeOut) { validate(); httpRequest.setTimeOut(timeOut); return this; }
/** @see HttpRequest#setIncludeCredentials(boolean) */ public HttpRequestBuilder includeCredentials (boolean includeCredentials) { validate(); httpRequest.setIncludeCredentials(includeCredentials); return this; }
/** @see HttpRequest#setHeader(String, String) */ public HttpRequestBuilder header (String name, String value) { validate(); httpRequest.setHeader(name, value); return this; }
/** Sets the {@code Authorization} header via the Base64 encoded username and password. */ public HttpRequestBuilder basicAuthentication (String username, String password) { validate(); httpRequest.setHeader(HttpRequestHeader.Authorization, "Basic " + Base64Coder.encodeString(username + ":" + password)); return this; }
/** Sets the correct {@code ContentType} and encodes the given parameter map, then sets it as the content. */ public HttpRequestBuilder formEncodedContent (Map<String, String> content) { validate(); httpRequest.setHeader(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded"); String formEncodedContent = HttpParametersUtils.convertHttpParameters(content); httpRequest.setContent(formEncodedContent); return this; }
/** Sets the correct {@code ContentType} and encodes the given content object via {@link #json}, then sets it as the content. */ public HttpRequestBuilder jsonContent (Object content) { validate(); httpRequest.setHeader(HttpRequestHeader.ContentType, "application/json"); String jsonContent = json.toJson(content); httpRequest.setContent(jsonContent); return this; }
/** Sets the correct {@code ContentType} and encodes the given content object via {@link #json}, then sets it as the content. */ public HttpRequestBuilder jsonContent (Object content) { validate(); httpRequest.setHeader(HttpRequestHeader.ContentType, "application/json"); String jsonContent = json.toJson(content); httpRequest.setContent(jsonContent); return this; }