Class HttpBase<T>
java.lang.Object
jodd.http.HttpBase<T>
- Direct Known Subclasses:
HttpRequest, HttpResponse
Base class for
HttpRequest and HttpResponse.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected booleanprotected Stringprotected HttpMultiMap<?> protected Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected final HeadersMultiMapstatic final Stringstatic final Stringprotected HttpProgressListenerprotected Stringprotected Stringprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TAdds or sets header parameter.protected void_headerRaw(String name, String value, boolean overwrite) Internal direct header setting.protected T_this()accept()Returns "Accept" header.Sets "Accept" header.Returns "Accept-Encoding" header.acceptEncoding(String encodings) Sets "Accept-Encoding" header.Sets raw body content and discards form parameters.Sets raw body content and discards all form parameters.byte[]Returns raw body bytes.bodyRaw()Returns raw body as received or set (always in ISO-8859-1 encoding).bodyText()Returnsbody contentas text.Definesbody text contentthat will be encoded asdefault body media typeindefault body encodingif missing.Definesbody text contentthat will be encoded indefault body encoding.Defines body text and content type (as media type and charset).protected abstract Bufferbuffer(boolean full) Createsbufferready to be consumed.booleanReturns whether header keys should be strict or not, when they are modified by changing them to PascalCase.capitalizeHeaderKeys(boolean capitalizeHeaderKeys) Sets headers behavior.charset()Returns charset, as defined by 'Content-Type' header.Defines just content type charset.connectionKeepAlive(boolean keepAlive) Defines "Connection" header as "Keep-Alive" or "Close".Returns "Content-Encoding" header.Returns full "Content-Length" header ornullif not set.contentLength(int value) Sets the full "Content-Length" header.Returns full "Content-Type" header.contentType(String contentType) Sets full "Content-Type" header.contentType(String mediaType, 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.Adds the form parameter.Sets many form parameters at once.Sets many form parameters at once.protected BufferCreates formbufferand sets few headers.formEncoding(String encoding) Defines encoding for forms parameters.formOverwrite(String name, Object value) Sets form parameter by overwriting.Returns value of header parameter.Addsintvalue as header parameter,Adds date value as header parameter.Adds header parameter.Adds many header parameters at once.Returns collection of all header names.headerOverwrite(String name, String value) Sets the header by overwriting it.voidheaderRemove(String name) Removes all header parameters for given name.Returns all values for given header name.Clears all headers.Returns HTTP version string.httpVersion(String httpVersion) Sets the HTTP version string.protected voidinitForm()Initializes form.booleanReturnstrueif connection is persistent.protected booleanReturnstrueif form containsUploadable.Returns media type, as defined by 'Content-Type' header.Defines just content media type.protected voidpopulateHeaderAndBody(Buffer target, Buffer formBuffer, boolean fullRequest) protected voidreadBody(BufferedReader reader) Parses body.protected voidreadHeaders(BufferedReader reader) Parses headers.protected StringResolves form encodings.voidsendTo(OutputStream out) Sends request or response to output stream.byte[]Returns byte array of request or response.Returns Bearer token ornullif not set.toString()Returns string representation of this request or response.toString(boolean fullResponse) Returns full request/response, or just headers.protected ObjectwrapFormValue(Object value) Wraps non-Strings form values withuploadable content.
-
Field Details
-
HEADER_ACCEPT
- See Also:
-
HEADER_AUTHORIZATION
- See Also:
-
HEADER_ACCEPT_ENCODING
- See Also:
-
HEADER_CONTENT_TYPE
- See Also:
-
HEADER_CONTENT_LENGTH
- See Also:
-
HEADER_CONTENT_ENCODING
- See Also:
-
HEADER_HOST
- See Also:
-
HEADER_ETAG
- See Also:
-
HEADER_CONNECTION
- See Also:
-
HEADER_KEEP_ALIVE
- See Also:
-
HEADER_CLOSE
- See Also:
-
HEADER_USER_AGENT
- See Also:
-
HTTP_1_0
- See Also:
-
HTTP_1_1
- See Also:
-
httpVersion
-
capitalizeHeaderKeys
protected boolean capitalizeHeaderKeys -
headers
-
form
-
body
-
charset
-
mediaType
-
formEncoding
-
multipart
protected boolean multipart -
httpProgressListener
-
-
Constructor Details
-
HttpBase
public HttpBase()
-
-
Method Details
-
_this
-
httpVersion
Returns HTTP version string. By default it's "HTTP/1.1". -
httpVersion
-
capitalizeHeaderKeys
public boolean capitalizeHeaderKeys()Returns whether header keys should be strict or not, when they are modified by changing them to PascalCase.- See Also:
-
capitalizeHeaderKeys
-
header
-
headers
-
headerRemove
Removes all header parameters for given name. -
headersClear
Clears all headers. -
header
Adds header parameter. If a header with the same name exist, it will not be overwritten, but the new header with the same name is going to be added. The order of header parameters is preserved. Also detects 'Content-Type' header and extractsmedia typeandcharsetvalues. -
header
-
headerOverwrite
-
_header
-
_headerRaw
-
header
-
header
-
headerNames
Returns collection of all header names. Depends oncapitalizeHeaderKeys()flag. -
tokenAuthentication
Returns Bearer token ornullif not set. -
charset
Returns charset, as defined by 'Content-Type' header. If not set, returnsnull- indicating the default charset (ISO-8859-1). -
charset
-
mediaType
Returns media type, as defined by 'Content-Type' header. If not set, returnsnull- indicating the default media type, depending on request/response. -
mediaType
-
contentType
Returns full "Content-Type" header. It consists ofmedia typeandcharset. -
contentType
Sets full "Content-Type" header. Bothmedia typeandcharsetare overridden. -
contentType
Sets "Content-Type" header by defining media-type and/or charset parameter. This method may be used to update media-type and/or charset by passing non-nullvalue for changes.Important: if Content-Type header has some other parameters, they will be removed!
-
connectionKeepAlive
Defines "Connection" header as "Keep-Alive" or "Close". Existing value is overwritten. -
isConnectionPersistent
public boolean isConnectionPersistent()Returnstrueif connection is persistent. If "Connection" header does not exist, returnstruefor HTTP 1.1 andfalsefor 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.
-
contentLength
Returns full "Content-Length" header ornullif not set. Returned value is raw and unchecked, exactly the same as it was specified or received. It may be even invalid. -
contentLength
Sets the full "Content-Length" header. -
contentEncoding
Returns "Content-Encoding" header. -
accept
Returns "Accept" header. -
accept
-
acceptEncoding
Returns "Accept-Encoding" header. -
acceptEncoding
-
initForm
protected void initForm()Initializes form. -
wrapFormValue
Wraps non-Strings form values withuploadable content. Detects invalid types and throws an exception. So all uploadable values are of the same type. -
form
-
formOverwrite
-
form
-
form
-
form
Return map of form parameters. Note that all uploadable values are wrapped withUploadable. -
formEncoding
Defines encoding for forms parameters. Default value is copied fromHttpBase.Defaults.formEncoding. It is overridden bycharsetvalue. -
cookies
Parses cookie information from the header. -
bodyRaw
Returns raw body as received or set (always in ISO-8859-1 encoding). If body content is a text, usebodyText()to get it converted. Returnsnullif body is not specified! -
bodyBytes
public byte[] bodyBytes()Returns raw body bytes. Returns empty array if body is not specified. -
bodyText
Returnsbody contentas text. Ifcharset parameterof "Content-Type" header is defined, body string charset is converted, otherwise the same raw body content is returned. Never returnsnull. -
body
-
bodyText
Defines body text and content type (as media type and charset). Body string will be converted toraw body stringand "Content-Type" header will be set. -
bodyText
Definesbody text contentthat will be encoded indefault body encoding. -
bodyText
Definesbody text contentthat will be encoded asdefault body media typeindefault body encodingif missing. -
body
-
isFormMultipart
protected boolean isFormMultipart()Returnstrueif form containsUploadable. -
formBuffer
-
resolveFormEncoding
Resolves form encodings. -
toString
-
toString
Returns full request/response, or just headers. Useful for debugging. -
toByteArray
public byte[] toByteArray()Returns byte array of request or response. -
buffer
-
populateHeaderAndBody
-
sendTo
Sends request or response to output stream.- Throws:
IOException
-
readHeaders
Parses headers. -
readBody
Parses body.
-