public abstract static class HttpRequest.Builder
extends java.lang.Object
HttpRequest
s. HttpRequest.Builder
s
are created by calling HttpRequest.create(URI)
or
HttpClient.request(URI)
.
Each of the setter methods in this class modifies the state of the builder and returns this (ie. the same instance). The methods are not synchronized and should not be called from multiple threads without external synchronization.
The build methods return a new HttpRequest
each time they are
called.
Modifier and Type | Method and Description |
---|---|
abstract HttpRequest.Builder |
body(HttpRequest.BodyProcessor reqproc)
Sets a request body for this builder.
|
abstract HttpRequest.Builder |
copy()
Returns an exact duplicate copy of this Builder based on current
state.
|
abstract HttpRequest.Builder |
expectContinue(boolean enable)
Request server to acknowledge request before sending request
body.
|
abstract HttpRequest.Builder |
followRedirects(HttpClient.Redirect policy)
Specifies whether this request will automatically follow redirects
issued by the server.
|
abstract HttpRequest |
GET()
Builds and returns a GET
HttpRequest from this builder. |
abstract HttpRequest.Builder |
header(java.lang.String name,
java.lang.String value)
Adds the given name value pair to the set of headers for this
request.
|
abstract HttpRequest.Builder |
headers(java.lang.String... headers)
Adds the given name value pairs to the set of headers for this
request.
|
abstract HttpRequest |
method(java.lang.String method)
Builds and returns a
HttpRequest from this builder using
the given method String. |
abstract HttpRequest |
POST()
Builds and returns a POST
HttpRequest from this builder. |
abstract HttpRequest.Builder |
proxy(java.net.ProxySelector proxy)
Overrides the ProxySelector set on the request's client
for this request.
|
abstract HttpRequest |
PUT()
Builds and returns a PUT
HttpRequest from this builder. |
abstract HttpRequest.Builder |
setHeader(java.lang.String name,
java.lang.String value)
Sets the given name value pair to the set of headers for this
request.
|
abstract HttpRequest.Builder |
timeout(java.util.concurrent.TimeUnit unit,
long timeval)
Sets a timeout for this request.
|
abstract HttpRequest.Builder |
uri(java.net.URI uri)
Sets this HttpRequest's request URI.
|
abstract HttpRequest.Builder |
version(HttpClient.Version version)
Overrides the
HttpClient.version() setting for this
request. |
public abstract HttpRequest.Builder uri(java.net.URI uri)
uri
- the request URIpublic abstract HttpRequest.Builder followRedirects(HttpClient.Redirect policy)
HttpClient.followRedirects()
policy
- the redirection policypublic abstract HttpRequest.Builder expectContinue(boolean enable)
enable
- true
if Expect continue to be sentpublic abstract HttpRequest.Builder version(HttpClient.Version version)
HttpClient.version()
setting for this
request.version
- the HTTP protocol version requestedpublic abstract HttpRequest.Builder header(java.lang.String name, java.lang.String value)
name
- the header namevalue
- the header valuepublic abstract HttpRequest.Builder proxy(java.net.ProxySelector proxy)
proxy
- the ProxySelector to usepublic abstract HttpRequest.Builder headers(java.lang.String... headers)
headers
- the list of String name value pairsjava.lang.IllegalArgumentException
- if there isn't an even
number of parameterspublic abstract HttpRequest.Builder timeout(java.util.concurrent.TimeUnit unit, long timeval)
HttpTimeoutException
is thrown
from HttpRequest.response()
or HttpRequest.responseAsync()
completes
exceptionally with a HttpTimeoutException
.unit
- the timeout unitstimeval
- the number of units to wait forpublic abstract HttpRequest.Builder setHeader(java.lang.String name, java.lang.String value)
name
- the header namevalue
- the header valuepublic abstract HttpRequest.Builder body(HttpRequest.BodyProcessor reqproc)
HttpRequest
for example BodyProcessor
implementations.
If no body is specified, then no body is sent with the request.reqproc
- the request body processorpublic abstract HttpRequest GET()
HttpRequest
from this builder.HttpRequest
public abstract HttpRequest POST()
HttpRequest
from this builder.HttpRequest
public abstract HttpRequest PUT()
HttpRequest
from this builder.HttpRequest
public abstract HttpRequest method(java.lang.String method)
HttpRequest
from this builder using
the given method String. The method string is case-sensitive, and
may be rejected if an upper-case string is not used.method
- the method to useHttpRequest
java.lang.IllegalArgumentException
- if an unrecognised method is usedpublic abstract HttpRequest.Builder copy()