public abstract class HttpBase<T>
extends java.lang.Object
HttpRequest
and HttpResponse
.Modifier and Type | Class and Description |
---|---|
static class |
HttpBase.Defaults |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
body |
protected boolean |
capitalizeHeaderKeys |
protected java.lang.String |
charset |
protected HttpMultiMap<?> |
form |
protected java.lang.String |
formEncoding |
static java.lang.String |
HEADER_ACCEPT |
static java.lang.String |
HEADER_ACCEPT_ENCODING |
static java.lang.String |
HEADER_AUTHORIZATION |
static java.lang.String |
HEADER_CLOSE |
static java.lang.String |
HEADER_CONNECTION |
static java.lang.String |
HEADER_CONTENT_ENCODING |
static java.lang.String |
HEADER_CONTENT_LENGTH |
static java.lang.String |
HEADER_CONTENT_TYPE |
static java.lang.String |
HEADER_ETAG |
static java.lang.String |
HEADER_HOST |
static java.lang.String |
HEADER_KEEP_ALIVE |
protected HeadersMultiMap |
headers |
static java.lang.String |
HTTP_1_0 |
static java.lang.String |
HTTP_1_1 |
protected HttpProgressListener |
httpProgressListener |
protected java.lang.String |
httpVersion |
protected java.lang.String |
mediaType |
protected boolean |
multipart |
Constructor and Description |
---|
HttpBase() |
Modifier and Type | Method and Description |
---|---|
protected T |
_header(java.lang.String name,
java.lang.String value,
boolean overwrite)
Adds or sets header parameter.
|
protected void |
_headerRaw(java.lang.String name,
java.lang.String value,
boolean overwrite)
Internal direct header setting.
|
protected T |
_this() |
java.lang.String |
accept()
Returns "Accept" header.
|
T |
accept(java.lang.String encodings)
Sets "Accept" header.
|
java.lang.String |
acceptEncoding()
Returns "Accept-Encoding" header.
|
T |
acceptEncoding(java.lang.String encodings)
Sets "Accept-Encoding" header.
|
java.lang.String |
body()
Returns raw body as received or set (always in ISO-8859-1 encoding).
|
T |
body(byte[] content,
java.lang.String contentType)
Sets raw body content and discards form parameters.
|
T |
body(java.lang.String body)
Sets raw body content and discards all form parameters.
|
byte[] |
bodyBytes()
Returns raw body bytes.
|
java.lang.String |
bodyText()
Returns
body content as text. |
T |
bodyText(java.lang.String body)
Defines
body text content
that will be encoded as default body media type
in default body encoding if missing. |
T |
bodyText(java.lang.String body,
java.lang.String mediaType)
Defines
body text content
that will be encoded in default body encoding . |
T |
bodyText(java.lang.String body,
java.lang.String mediaType,
java.lang.String charset)
Defines body text and content type (as media type and charset).
|
protected abstract Buffer |
buffer(boolean full)
Creates
buffer ready to be consumed. |
boolean |
capitalizeHeaderKeys()
Returns whether header keys should be strict or not, when they are
modified by changing them to PascalCase.
|
T |
capitalizeHeaderKeys(boolean capitalizeHeaderKeys)
Sets headers behavior.
|
java.lang.String |
charset()
Returns charset, as defined by 'Content-Type' header.
|
T |
charset(java.lang.String charset)
Defines just content type charset.
|
T |
connectionKeepAlive(boolean keepAlive)
Defines "Connection" header as "Keep-Alive" or "Close".
|
java.lang.String |
contentEncoding()
Returns "Content-Encoding" header.
|
java.lang.String |
contentLength()
Returns full "Content-Length" header or
null if not set. |
T |
contentLength(int value)
Sets the full "Content-Length" header.
|
java.lang.String |
contentType()
Returns full "Content-Type" header.
|
T |
contentType(java.lang.String contentType)
Sets full "Content-Type" header.
|
T |
contentType(java.lang.String mediaType,
java.lang.String charset)
Sets "Content-Type" header by defining media-type and/or charset parameter.
|
Cookie[] |
cookies()
Parses cookie information from the header.
|
HttpMultiMap<?> |
form()
Return map of form parameters.
|
T |
form(java.util.Map<java.lang.String,java.lang.Object> formMap)
Sets many form parameters at once.
|
T |
form(java.lang.String name,
java.lang.Object value)
Adds the form parameter.
|
T |
form(java.lang.String name,
java.lang.Object value,
java.lang.Object... parameters)
Sets many form parameters at once.
|
protected Buffer |
formBuffer()
Creates form
buffer and sets few headers. |
T |
formEncoding(java.lang.String encoding)
Defines encoding for forms parameters.
|
T |
formOverwrite(java.lang.String name,
java.lang.Object value)
Sets form parameter by overwriting.
|
T |
header(java.util.Map<java.lang.String,java.lang.String> headerMap)
Adds many header parameters at once.
|
java.lang.String |
header(java.lang.String name)
Returns value of header parameter.
|
T |
header(java.lang.String name,
int value)
Adds
int value as header parameter, |
T |
header(java.lang.String name,
long millis)
Adds date value as header parameter.
|
T |
header(java.lang.String name,
java.lang.String value)
Adds header parameter.
|
java.util.Collection<java.lang.String> |
headerNames()
Returns collection of all header names.
|
T |
headerOverwrite(java.lang.String name,
java.lang.String value)
Sets the header by overwriting it.
|
void |
headerRemove(java.lang.String name)
Removes all header parameters for given name.
|
java.util.List<java.lang.String> |
headers(java.lang.String name)
Returns all values for given header name.
|
java.lang.String |
httpVersion()
Returns HTTP version string.
|
T |
httpVersion(java.lang.String httpVersion)
Sets the HTTP version string.
|
protected void |
initForm()
Initializes form.
|
boolean |
isConnectionPersistent()
Returns
true if connection is persistent. |
protected boolean |
isFormMultipart()
Returns
true if form contains Uploadable . |
java.lang.String |
mediaType()
Returns media type, as defined by 'Content-Type' header.
|
T |
mediaType(java.lang.String mediaType)
Defines just content media type.
|
protected void |
populateHeaderAndBody(Buffer target,
Buffer formBuffer,
boolean fullRequest) |
protected void |
readBody(java.io.BufferedReader reader)
Parses body.
|
protected void |
readHeaders(java.io.BufferedReader reader)
Parses headers.
|
protected java.lang.String |
resolveFormEncoding()
Resolves form encodings.
|
void |
sendTo(java.io.OutputStream out)
Sends request or response to output stream.
|
byte[] |
toByteArray()
Returns byte array of request or response.
|
java.lang.String |
tokenAuthentication()
Returns Bearer token or
null if not set. |
java.lang.String |
toString()
Returns string representation of this request or response.
|
java.lang.String |
toString(boolean fullResponse)
Returns full request/response, or just headers.
|
protected java.lang.Object |
wrapFormValue(java.lang.Object value)
Wraps non-Strings form values with
uploadable content . |
public static final java.lang.String HEADER_ACCEPT
public static final java.lang.String HEADER_AUTHORIZATION
public static final java.lang.String HEADER_ACCEPT_ENCODING
public static final java.lang.String HEADER_CONTENT_TYPE
public static final java.lang.String HEADER_CONTENT_LENGTH
public static final java.lang.String HEADER_CONTENT_ENCODING
public static final java.lang.String HEADER_HOST
public static final java.lang.String HEADER_ETAG
public static final java.lang.String HEADER_CONNECTION
public static final java.lang.String HEADER_KEEP_ALIVE
public static final java.lang.String HEADER_CLOSE
public static final java.lang.String HTTP_1_0
public static final java.lang.String HTTP_1_1
protected java.lang.String httpVersion
protected boolean capitalizeHeaderKeys
protected final HeadersMultiMap headers
protected HttpMultiMap<?> form
protected java.lang.String body
protected java.lang.String charset
protected java.lang.String mediaType
protected java.lang.String formEncoding
protected boolean multipart
protected HttpProgressListener httpProgressListener
protected T _this()
public java.lang.String httpVersion()
public T httpVersion(java.lang.String httpVersion)
public boolean capitalizeHeaderKeys()
capitalizeHeaderKeys()
public T capitalizeHeaderKeys(boolean capitalizeHeaderKeys)
capitalizeHeaderKeys()
public java.lang.String header(java.lang.String name)
null
if header doesn't exist.public java.util.List<java.lang.String> headers(java.lang.String name)
public void headerRemove(java.lang.String name)
public T header(java.lang.String name, java.lang.String value)
media type
and charset
values.public T header(java.util.Map<java.lang.String,java.lang.String> headerMap)
header(String, String)
public T headerOverwrite(java.lang.String name, java.lang.String value)
header(String, String)
protected T _header(java.lang.String name, java.lang.String value, boolean overwrite)
header(String, String)
protected void _headerRaw(java.lang.String name, java.lang.String value, boolean overwrite)
public T header(java.lang.String name, int value)
int
value as header parameter,header(String, String)
public T header(java.lang.String name, long millis)
header(String, String)
public java.util.Collection<java.lang.String> headerNames()
capitalizeHeaderKeys()
flag.public java.lang.String tokenAuthentication()
null
if not set.public java.lang.String charset()
null
- indicating
the default charset (ISO-8859-1).public T charset(java.lang.String charset)
null
will remove the charset information from
the header.public java.lang.String mediaType()
null
- indicating
the default media type, depending on request/response.public T mediaType(java.lang.String mediaType)
null
will
not have any effects.public java.lang.String contentType()
media type
and charset
.public T contentType(java.lang.String contentType)
media type
and charset
are overridden.public T contentType(java.lang.String mediaType, java.lang.String charset)
null
value for changes.
Important: if Content-Type header has some other parameters, they will be removed!
public T connectionKeepAlive(boolean keepAlive)
public boolean isConnectionPersistent()
true
if connection is persistent.
If "Connection" header does not exist, returns true
for HTTP 1.1 and false
for HTTP 1.0. If
"Connection" header exist, checks if it is equal to "Close".
In HTTP 1.1, all connections are considered persistent unless declared otherwise. Under HTTP 1.0, there is no official specification for how keepalive operates.
public java.lang.String contentLength()
null
if not set. Returned value is raw and unchecked, exactly the same
as it was specified or received. It may be even invalid.public T contentLength(int value)
public java.lang.String contentEncoding()
public java.lang.String accept()
public T accept(java.lang.String encodings)
public java.lang.String acceptEncoding()
public T acceptEncoding(java.lang.String encodings)
protected void initForm()
protected java.lang.Object wrapFormValue(java.lang.Object value)
uploadable content
.
Detects invalid types and throws an exception. So all uploadable values
are of the same type.public T form(java.lang.String name, java.lang.Object value)
public T formOverwrite(java.lang.String name, java.lang.Object value)
public T form(java.lang.String name, java.lang.Object value, java.lang.Object... parameters)
public T form(java.util.Map<java.lang.String,java.lang.Object> formMap)
public HttpMultiMap<?> form()
Uploadable
.public T formEncoding(java.lang.String encoding)
formEncoding(java.lang.String)
.
It is overridden by charset
value.public Cookie[] cookies()
public java.lang.String body()
bodyText()
to get it converted.
Returns null
if body is not specified!public byte[] bodyBytes()
null
if body is not specified.public java.lang.String bodyText()
body content
as text. If charset parameter
of "Content-Type" header is defined, body string charset is converted, otherwise
the same raw body content is returned. Never returns null
.public T body(java.lang.String body)
public T bodyText(java.lang.String body, java.lang.String mediaType, java.lang.String charset)
raw body string
and "Content-Type" header will be set.public T bodyText(java.lang.String body, java.lang.String mediaType)
body text content
that will be encoded in default body encoding
.public T bodyText(java.lang.String body)
body text content
that will be encoded as default body media type
in default body encoding
if missing.public T body(byte[] content, java.lang.String contentType)
body(String)
protected boolean isFormMultipart()
true
if form contains Uploadable
.protected java.lang.String resolveFormEncoding()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean fullResponse)
public byte[] toByteArray()
protected abstract Buffer buffer(boolean full)
buffer
ready to be consumed.
Buffer can, optionally, contains just headers.protected void populateHeaderAndBody(Buffer target, Buffer formBuffer, boolean fullRequest)
public void sendTo(java.io.OutputStream out) throws java.io.IOException
java.io.IOException
protected void readHeaders(java.io.BufferedReader reader)
protected void readBody(java.io.BufferedReader reader)
Copyright © 2003-present Jodd Team