public class HttpRequest extends HttpBase<HttpRequest>
HttpBase.Defaults
Modifier and Type | Field and Description |
---|---|
protected int |
connectTimeout |
protected boolean |
followRedirects |
protected java.lang.String |
host |
protected HttpConnection |
httpConnection |
protected HttpConnectionProvider |
httpConnectionProvider |
protected int |
maxRedirects |
protected java.lang.String |
method |
protected java.lang.String |
path |
protected int |
port |
protected java.lang.String |
protocol |
protected HttpMultiMap<java.lang.String> |
query |
protected java.lang.String |
queryEncoding |
protected int |
timeout |
body, capitalizeHeaderKeys, charset, form, formEncoding, HEADER_ACCEPT, HEADER_ACCEPT_ENCODING, HEADER_AUTHORIZATION, HEADER_CLOSE, HEADER_CONNECTION, HEADER_CONTENT_ENCODING, HEADER_CONTENT_LENGTH, HEADER_CONTENT_TYPE, HEADER_ETAG, HEADER_HOST, HEADER_KEEP_ALIVE, headers, HTTP_1_0, HTTP_1_1, httpProgressListener, httpVersion, mediaType, multipart
Constructor and Description |
---|
HttpRequest() |
Modifier and Type | Method and Description |
---|---|
HttpRequest |
acceptJson()
Accepts JSON content type.
|
HttpRequest |
basicAuthentication(java.lang.String username,
java.lang.String password)
Enables basic authentication by adding required header.
|
protected Buffer |
buffer(boolean fullRequest)
Prepares the request buffer.
|
HttpRequest |
clearQueries()
Clears all query parameters.
|
static HttpRequest |
connect(java.lang.String destination)
Builds a CONNECT request.
|
HttpConnection |
connection()
Returns
HttpConnection that is going to be
used for sending this request. |
HttpConnectionProvider |
connectionProvider()
Returns http connection provider that was used for creating
current http connection.
|
int |
connectionTimeout()
Returns socket connection timeout.
|
HttpRequest |
connectionTimeout(int milliseconds)
Defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout
for waiting for data or, put differently, a maximum period inactivity between
two consecutive data packets).
|
HttpRequest |
contentTypeJson()
Specifies JSON content type.
|
HttpRequest |
cookies(Cookie... cookies)
Sets cookies to the request.
|
static HttpRequest |
create(java.lang.String method,
java.lang.String destination)
Generic request builder, usually used when method is a variable.
|
static HttpRequest |
delete(java.lang.String destination)
Builds a DELETE request.
|
HttpRequest |
followRedirects(boolean followRedirects)
Defines if redirects responses should be followed.
|
static HttpRequest |
get(java.lang.String destination)
Builds a GET request.
|
static HttpRequest |
head(java.lang.String destination)
Builds a HEAD request.
|
java.lang.String |
host()
Returns request host name.
|
HttpRequest |
host(java.lang.String host)
Sets request host name.
|
java.lang.String |
hostUrl()
Returns just host url, without path and query.
|
protected void |
initRequest()
Prepares request on creation.
|
boolean |
isFollowRedirects()
Returns
true if redirects are followed. |
HttpRequest |
keepAlive(HttpResponse httpResponse,
boolean doContinue)
Continues using the same keep-alive connection.
|
int |
maxRedirects()
Returns max number of redirects, used when
followRedirects is enabled. |
HttpRequest |
maxRedirects(int maxRedirects)
Sets the max number of redirects, used when
followRedirects is enabled. |
java.lang.String |
method()
Returns request method.
|
HttpRequest |
method(HttpMethod httpMethod) |
HttpRequest |
method(java.lang.String method)
Specifies request method.
|
HttpRequest |
monitor(HttpProgressListener httpProgressListener)
Registers
listener that will
monitor upload progress. |
HttpRequest |
multipart(boolean multipart)
Forces multipart requests.
|
HttpRequest |
open()
Opens a new
connection using either
provided or default connection
provider. |
HttpRequest |
open(HttpConnection httpConnection)
Assignees provided
HttpConnection for communication. |
HttpRequest |
open(HttpConnectionProvider httpConnectionProvider)
Opens a new
connection
using given HttpConnectionProvider . |
static HttpRequest |
options(java.lang.String destination)
Builds an OPTIONS request.
|
static HttpRequest |
patch(java.lang.String destination)
Builds a PATCH request.
|
java.lang.String |
path()
Returns request path, without the query.
|
HttpRequest |
path(java.lang.String path)
Sets request path.
|
int |
port()
Returns request port number.
|
HttpRequest |
port(int port)
Sets request port number.
|
static HttpRequest |
post(java.lang.String destination)
Builds a POST request.
|
java.lang.String |
protocol()
Returns used protocol.
|
HttpRequest |
protocol(java.lang.String protocol)
Defines protocol.
|
static HttpRequest |
put(java.lang.String destination)
Builds a PUT request.
|
HttpMultiMap<java.lang.String> |
query()
Returns backend map of query parameters.
|
HttpRequest |
query(java.util.Map<java.lang.String,java.lang.String> queryMap)
Adds all parameters from the provided map.
|
HttpRequest |
query(java.lang.String name1,
java.lang.Object value1,
java.lang.Object... parameters)
Adds many query parameters at once.
|
HttpRequest |
query(java.lang.String name,
java.lang.String value)
Adds query parameter.
|
HttpRequest |
queryEncoding(java.lang.String encoding)
Defines encoding for query parameters.
|
HttpRequest |
queryRemove(java.lang.String name)
Removes query parameters for given name.
|
java.lang.String |
queryString()
Generates query string.
|
HttpRequest |
queryString(java.lang.String queryString) |
HttpRequest |
queryString(java.lang.String queryString,
boolean decode)
Sets query from provided query string.
|
static HttpRequest |
readFrom(java.io.InputStream in)
Parses input stream and creates new
HttpRequest object. |
static HttpRequest |
readFrom(java.io.InputStream in,
java.lang.String encoding) |
HttpResponse |
send()
Opens connection if not already open, sends request,
reads response and closes the request. |
void |
sendAndReceive(java.util.function.Consumer<HttpResponse> responseHandler)
Syntax sugar.
|
<R> R |
sendAndReceive(java.util.function.Function<HttpResponse,R> responseHandler)
Syntax sugar.
|
java.util.concurrent.CompletableFuture<HttpResponse> |
sendAsync()
Sends http request asynchronously using common fork-join pool.
|
HttpRequest |
set(java.lang.String destination)
Sets the destination (method, host, port... ) at once.
|
HttpRequest |
setHostHeader()
Sets 'Host' header from current host and port.
|
int |
timeout()
Returns read timeout (SO_TIMEOUT) in milliseconds.
|
HttpRequest |
timeout(int milliseconds)
Defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or,
put differently, a maximum period inactivity between two consecutive data packets).
|
HttpRequest |
tokenAuthentication(java.lang.String token)
Enables token-based authentication.
|
static HttpRequest |
trace(java.lang.String destination)
Builds a TRACE request.
|
boolean |
trustAllCertificates()
Returns a flag if to trusts all certificates.
|
HttpRequest |
trustAllCerts(boolean trust)
Trusts all certificates, use with caution.
|
java.lang.String |
url()
Returns full URL path.
|
boolean |
verifyHttpsHost()
Returns a flag if to verify https hosts.
|
HttpRequest |
verifyHttpsHost(boolean verifyHttpsHost)
Verifies HTTPS hosts.
|
HttpRequest |
withConnectionProvider(HttpConnectionProvider httpConnectionProvider)
Uses custom connection provider when
opening the
connection. |
_header, _headerRaw, _this, accept, accept, acceptEncoding, acceptEncoding, body, body, body, bodyBytes, bodyText, bodyText, bodyText, bodyText, capitalizeHeaderKeys, capitalizeHeaderKeys, charset, charset, connectionKeepAlive, contentEncoding, contentLength, contentLength, contentType, contentType, contentType, cookies, form, form, form, form, formBuffer, formEncoding, formOverwrite, header, header, header, header, header, headerNames, headerOverwrite, headerRemove, headers, httpVersion, httpVersion, initForm, isConnectionPersistent, isFormMultipart, mediaType, mediaType, populateHeaderAndBody, readBody, readHeaders, resolveFormEncoding, sendTo, toByteArray, tokenAuthentication, toString, toString, wrapFormValue
protected java.lang.String protocol
protected java.lang.String host
protected int port
protected java.lang.String method
protected java.lang.String path
protected HttpMultiMap<java.lang.String> query
protected java.lang.String queryEncoding
protected int timeout
protected int connectTimeout
protected boolean followRedirects
protected int maxRedirects
protected HttpConnection httpConnection
protected HttpConnectionProvider httpConnectionProvider
protected void initRequest()
public java.lang.String host()
public HttpRequest host(java.lang.String host)
public java.lang.String protocol()
public HttpRequest protocol(java.lang.String protocol)
public int port()
public HttpRequest port(int port)
public HttpRequest set(java.lang.String destination)
public static HttpRequest create(java.lang.String method, java.lang.String destination)
public static HttpRequest connect(java.lang.String destination)
public static HttpRequest get(java.lang.String destination)
public static HttpRequest post(java.lang.String destination)
public static HttpRequest put(java.lang.String destination)
public static HttpRequest patch(java.lang.String destination)
public static HttpRequest delete(java.lang.String destination)
public static HttpRequest head(java.lang.String destination)
public static HttpRequest trace(java.lang.String destination)
public static HttpRequest options(java.lang.String destination)
public java.lang.String method()
public HttpRequest method(java.lang.String method)
public HttpRequest method(HttpMethod httpMethod)
public java.lang.String path()
public HttpRequest path(java.lang.String path)
query()
public HttpRequest multipart(boolean multipart)
false
,
it will be detected
if request
should be multipart. By setting this to true
we are forcing usage of multipart request.public HttpRequest cookies(Cookie... cookies)
public HttpRequest query(java.lang.String name, java.lang.String value)
public HttpRequest query(java.lang.String name1, java.lang.Object value1, java.lang.Object... parameters)
public HttpRequest query(java.util.Map<java.lang.String,java.lang.String> queryMap)
public HttpMultiMap<java.lang.String> query()
public HttpRequest clearQueries()
public HttpRequest queryRemove(java.lang.String name)
public HttpRequest queryString(java.lang.String queryString)
queryString(String, boolean)
public HttpRequest queryString(java.lang.String queryString, boolean decode)
public java.lang.String queryString()
public HttpRequest queryEncoding(java.lang.String encoding)
public java.lang.String url()
public java.lang.String hostUrl()
public HttpRequest basicAuthentication(java.lang.String username, java.lang.String password)
public HttpRequest tokenAuthentication(java.lang.String token)
public HttpRequest trustAllCerts(boolean trust)
public boolean trustAllCertificates()
public HttpRequest verifyHttpsHost(boolean verifyHttpsHost)
public boolean verifyHttpsHost()
public HttpRequest setHostHeader()
public HttpRequest monitor(HttpProgressListener httpProgressListener)
listener
that will
monitor upload progress. Be aware that the whole size of the
request is being monitored, not only the files content.public HttpRequest timeout(int milliseconds)
HttpConnection.setTimeout(int)
public int timeout()
timeout(int)
public HttpRequest connectionTimeout(int milliseconds)
public int connectionTimeout()
connectionTimeout(int)
public HttpRequest followRedirects(boolean followRedirects)
public boolean isFollowRedirects()
true
if redirects are followed.public HttpRequest maxRedirects(int maxRedirects)
followRedirects
is enabled.public int maxRedirects()
followRedirects
is enabled.public HttpRequest withConnectionProvider(HttpConnectionProvider httpConnectionProvider)
opening
the
connection.public HttpConnectionProvider connectionProvider()
null
, default
connection provider will be used.public HttpConnection connection()
HttpConnection
that is going to be
used for sending this request. Value is available
ONLY after calling open()
and before send()
.public HttpRequest open()
connection
using either
provided or default
connection
provider.public HttpRequest open(HttpConnectionProvider httpConnectionProvider)
connection
using given HttpConnectionProvider
.public HttpRequest open(HttpConnection httpConnection)
HttpConnection
for communication.
It does not actually opens it until the sending
.public HttpRequest keepAlive(HttpResponse httpResponse, boolean doContinue)
open()
when
continuing the communication!
First it checks if "Connection" header exist in the response
and if it is equal to "Keep-Alive" value. Then it
checks the "Keep-Alive" headers "max" parameter.
If its value is positive, then the existing HttpConnection
from the request will be reused. If max value is 1,
connection will be sent with "Connection: Close" header, indicating
its the last request. When new connection is created, the
same HttpConnectionProvider
that was used for
creating initial connection is used for opening the new connection.doContinue
- set it to false
to indicate the last connectionpublic HttpResponse send()
Opens connection
if not already open, sends request,
reads response and closes the request. If keep-alive mode is enabled
connection will not be closed.protected Buffer buffer(boolean fullRequest)
buffer
in class HttpBase<HttpRequest>
public static HttpRequest readFrom(java.io.InputStream in)
HttpRequest
object.
Assumes input stream is in ISO_8859_1 encoding.public static HttpRequest readFrom(java.io.InputStream in, java.lang.String encoding)
public HttpRequest contentTypeJson()
public HttpRequest acceptJson()
public java.util.concurrent.CompletableFuture<HttpResponse> sendAsync()
public <R> R sendAndReceive(java.util.function.Function<HttpResponse,R> responseHandler)
public void sendAndReceive(java.util.function.Consumer<HttpResponse> responseHandler)
Copyright © 2003-present Jodd Team