Class HttpObject
-
Nested Class Summary
Nested classes/interfaces inherited from class java.net.http.HttpRequest
HttpRequest.BodyPublisher, HttpRequest.BodyPublishers, HttpRequest.Builder -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]static final Stringprotected final HttpExchangeprotected berlin.yuna.typemap.model.TypeMapstatic final DateTimeFormatterstatic final Stringprotected HttpMethodprotected Stringprotected berlin.yuna.typemap.model.TypeMapprotected berlin.yuna.typemap.model.TypeMapprotected intprotected Longstatic final String[]static final String[] -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aHttpObject.HttpObject(HttpExchange exchange) Constructs a newHttpObjectfrom a specifiedHttpExchange. -
Method Summary
Modifier and TypeMethodDescriptionaccept()accept(ContentType... contentType) acceptLanguages(Locale... locales) Sets the accepted languages based on a list where the order indicates priority.accepts()address()Retrieves theInetAddressfrom theHttpExchange.Parses and returns any authentication token found in theHttpHeaders.AUTHORIZATIONheader.authToken(int index) Parses and returns any authentication token found in theHttpHeaders.AUTHORIZATIONheader.String[]Parses and returns any authentication token found in theHttpHeaders.AUTHORIZATIONheader.byte[]body()Returns a string representation of the body, decoded using theCharsetfromencoding()specified in theHttpHeaders.CONTENT_TYPEheader.body(byte[] body) Sets thebody()from aTypeInfoobject.body(Collection<?> body) Sets thebody()from aCollectionobject, encoding it into JSON format using theCharsetfromencoding().berlin.yuna.typemap.model.TypeInfo<?> Returns a string representation of thebody(), decoded using theCharsetfromencoding()specified in theHttpHeaders.CONTENT_TYPEheader.Returns a string representation of thebody(), decoded using theCharsetfromencoding()specified in theHttpHeaders.CONTENT_TYPEheader.berlin.yuna.typemap.model.TypeInfo<?> Returns a string representation of thebody(), decoded using theCharsetfromencoding()specified in theHttpHeaders.CONTENT_TYPEheader.bodyT(berlin.yuna.typemap.model.TypeInfo<?> body) Sets thebody()from aTypeInfoobject, encoding it into JSON format using theCharsetfromencoding().computedHeaders(boolean isRequest) Constructs and returns a map of HTTP headers to be included in an HTTP response.booleancontainsHeader(String key) Checks if a specified header exists in theHttpObject.booleancontainsQueryParam(String key) Checks if a specific query parameter exists in theHttpObject.Retrieves the first content types specified in theHttpHeaders.CONTENT_TYPEheader.contentType(String... contentType) Sets theHttpHeaders.CONTENT_TYPEheader without specifying aCharset.contentType(Charset charset, String... contentType) Sets theHttpHeaders.CONTENT_TYPEheader with specifying aCharset.contentType(Charset charset, ContentType... contentType) Sets theHttpHeaders.CONTENT_TYPEheader with specifying aCharset.contentType(ContentType... contentType) Sets theHttpHeaders.CONTENT_TYPEheader without specifying aCharset.Retrieves a list of all content types specified in theHttpHeaders.CONTENT_TYPEheader.static berlin.yuna.typemap.model.TypeMapconvertHeaders(Map<String, ?> headers) Converts a map of simple header values to aTypeMapof headers.Creates and returns a new instance ofHttpObject.corsResponse(String origin) Creates and returns a new instance ofHttpObjectwith CORS handling.corsResponse(String origin, String methods) Creates and returns a new instance ofHttpObjectwith CORS handling.corsResponse(String origin, String methods, String headers) Creates and returns a new instance ofHttpObjectwith CORS handling.corsResponse(String origin, String methods, String headers, int maxAge) Creates and returns a new instance ofHttpObjectwith CORS handling.corsResponse(String origin, String methods, String headers, int maxAge, boolean credentials) Creates and returns a new instance ofHttpObjectwith CORS handling.encoding()Retrieves the character set encoding from theHttpHeaders.CONTENT_TYPEheader.exchange()Returns the associatedHttpExchangefor thisHttpObject.booleanfailure()Retrieves the failure exception from the HTTP headers, if present.Stores a failure exception within the HTTP headers.<T> TfromExchange(Function<HttpExchange, T> mapper) static ContentTypeguessContentType(HttpObject response, byte[] body) booleanbooleanhasAccept(ContentType... contentTypes) booleanhasAcceptEncoding(String... encodings) booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanhasContentEncoding(String... encodings) booleanhasContentType(String... contentTypes) booleanhasContentType(ContentType contentType) booleanhasContentType(ContentType... contentTypes) booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanChecks if the HTTP response headers contain an entry indicating an exception or failure.Retrieves the value of a specified header.Adds or replaces a header in the HTTP headers map.berlin.yuna.typemap.model.TypeMapReturns the HTTP headers map.Sets Http headers.Sets Http headers.headers()host()Retrieves the host name from theHttpExchangeif available, otherwise extracts it from theHttpHeaders.HOSTheader.booleanbooleanbooleanbooleanbooleanbooleanisDeflateCompressed(byte[] body) booleanDetermines if theHttpObjectoriginates from a standard web browser based on theHttpHeaders.USER_AGENTheader.static booleanisMethod(HttpObject request, HttpMethod method) booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanDetermines if theHttpObjectoriginates from a mobile device based on theHttpHeaders.USER_AGENTheader.booleanisZipCompressed(byte[] body) method()Returns the current HTTP method of this object.methodType(String method) Sets the HTTP method for this object.methodType(HttpMethod method) Sets the HTTP method for this object.origin()Retrieves the origin from the current request.Sets the origin header for the currentHttpObject.Determines the value for theAccess-Control-Allow-Originheader.path()Retrieves the current path of theHttpObjectwithout last '/'.Sets the path for thisHttpObject.booleanChecks if the currentpath()matches a specified expression.Retrieves the value of a specified path parameter.berlin.yuna.typemap.model.TypeMapRetrieves a map of path parameters extracted from the URL.intport()Retrieves the host port from theHttpExchangeif available, otherwise extracts it from theHttpHeaders.HOSTheader.protocol()Retrieves the protocol used in theHttpExchange.queryParam(String key) Retrieves the value of a specified query parameter.berlin.yuna.typemap.model.TypeMapRetrieves all query parameters from the currentHttpObject.protected berlin.yuna.typemap.model.TypeMapqueryParamsOf(String query) static StringremoveLast(String input, String removable) Sends an HTTP response using the currentHttpObjectas the response context.response()Creates and returns a new instance ofHttpObject.response(boolean cors) Creates and returns a new instance ofHttpObject.Sends an HTTP request using the providedHttpObject.send(Context context, Consumer<HttpObject> callback) Sends an HTTP request using the providedHttpObject.longsize()Calculates the size of the HTTP content.booleanChecks if the Range header has been set to request only the first byte of the content.sizeRequest(boolean sizeRequest) Sets the HTTP Range header to request only the first byte of the content.static <R> List<R> splitHeaderValue(Collection<String> value, Function<String, R> mapper) intRetrieves the current HTTP status code for theHttpObject.statusCode(int statusCode) Sets the HTTP status code for theHttpObject.successOrElse(Consumer<HttpObject> onSuccess, Consumer<HttpObject> onFailure) timeout()timeout(long timeoutMs) toString()uri()Retrieves theHttpHeaders.USER_AGENTheader from theHttpObject.Sets theHttpHeaders.USER_AGENTheader for theHttpObject.version()Methods inherited from class java.net.http.HttpRequest
equals, hashCode, newBuilder, newBuilder, newBuilder
-
Field Details
-
method
-
path
-
body
protected byte[] body -
headers
protected berlin.yuna.typemap.model.TypeMap headers -
queryParams
protected berlin.yuna.typemap.model.TypeMap queryParams -
pathParams
protected berlin.yuna.typemap.model.TypeMap pathParams -
statusCode
protected int statusCode -
timeoutMs
-
exchange
-
HTTP_EXCEPTION_HEADER
- See Also:
-
HTTP_DATE_FORMATTER
-
USER_AGENT_BROWSERS
-
USER_AGENT_MOBILE
-
CONTEXT_HTTP_CLIENT_KEY
- See Also:
-
JAVA_MANAGED_HEADERS
-
-
Constructor Details
-
HttpObject
Constructs a newHttpObjectfrom a specifiedHttpExchange. Initializes headers, method, and path. TheHttpExchangeis lazy loaded. Methods likebody()will trigger the loading of the request body.- Parameters:
exchange- the HttpExchange containing the request details.
-
HttpObject
public HttpObject()Constructs aHttpObject.
-
-
Method Details
-
methodType
Returns the current HTTP method of this object.- Returns:
- the current
HttpMethod.
-
methodType
Sets the HTTP method for this object.- Parameters:
method- the HTTP method as a string.nullif method is not one ofHttpMethod.- Returns:
- this
HttpObjectfor method chaining.
-
methodType
Sets the HTTP method for this object.- Parameters:
method- the HTTP method as an enumHttpMethod.- Returns:
- this
HttpObjectfor method chaining.
-
contentType
Retrieves the first content types specified in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- the primary
ContentTypeof the request, ornullif no content type is set.
-
contentTypes
Retrieves a list of all content types specified in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- a list of
ContentTypeobjects representing each content type specified.
-
contentType
Sets theHttpHeaders.CONTENT_TYPEheader without specifying aCharset.- Parameters:
contentType- array of content type strings to be set in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- this
HttpObjectto allow method chaining.
-
contentType
Sets theHttpHeaders.CONTENT_TYPEheader without specifying aCharset.- Parameters:
contentType- array of content type strings to be set in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- this
HttpObjectto allow method chaining.
-
contentType
Sets theHttpHeaders.CONTENT_TYPEheader with specifying aCharset.- Parameters:
charset- theCharsetto set for body encoding.contentType- array of content type strings to be set in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- this
HttpObjectto allow method chaining.
-
contentType
Sets theHttpHeaders.CONTENT_TYPEheader with specifying aCharset.- Parameters:
charset- theCharsetto set for body encoding.contentType- array of content type strings to be set in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- this
HttpObjectto allow method chaining.
-
accept
-
accepts
-
accept
-
accept
-
hasAccept
-
hasAccept
-
acceptEncoding
-
acceptEncodings
-
hasAcceptEncoding
-
contentEncoding
-
contentEncodings
-
hasContentEncoding
-
acceptLanguage
-
acceptLanguages
-
acceptLanguages
Sets the accepted languages based on a list where the order indicates priority. The first language in the list has the highest priority, automatically assigning descending priorities.- Parameters:
locales- Ordered array ofLocalerepresenting the preferred languages, from most to least preferred.- Returns:
- this
HttpObjectto allow method chaining.
-
path
Retrieves the current path of theHttpObjectwithout last '/'.- Returns:
- the request path.
-
path
Sets the path for thisHttpObject. This method also parses and sets the query parameters if they are included in the path.- Parameters:
path- the path to set, which may include query parameters.- Returns:
- this HttpObject to allow method chaining.
-
bodyAsString
Returns a string representation of thebody(), decoded using theCharsetfromencoding()specified in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- the body as a string.
-
bodyAsJson
public berlin.yuna.typemap.model.TypeInfo<?> bodyAsJson()Returns a string representation of thebody(), decoded using theCharsetfromencoding()specified in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- the body as a json.
-
bodyAsXml
public berlin.yuna.typemap.model.TypeInfo<?> bodyAsXml()Returns a string representation of thebody(), decoded using theCharsetfromencoding()specified in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- the body as a xml.
-
body
public byte[] body()Returns a string representation of the body, decoded using theCharsetfromencoding()specified in theHttpHeaders.CONTENT_TYPEheader.- Returns:
- the body as a xml.
-
bodyT
Sets thebody()from aTypeInfoobject, encoding it into JSON format using theCharsetfromencoding().- Parameters:
body- theTypeInforepresenting the body to be set.- Returns:
- this
HttpObjectto allow method chaining.
-
body
Sets thebody()from aCollectionobject, encoding it into JSON format using theCharsetfromencoding().- Parameters:
body- theCollectionrepresenting the body to be set.- Returns:
- this
HttpObjectto allow method chaining.
-
body
- Parameters:
body- theMaprepresenting the body to be set.- Returns:
- this
HttpObjectto allow method chaining.
-
body
- Parameters:
body- the String representing the body to be set.- Returns:
- this
HttpObjectto allow method chaining.
-
body
Sets thebody()from aTypeInfoobject.- Parameters:
body- the String representing the body to be set.- Returns:
- this
HttpObjectto allow method chaining.
-
queryParams
public berlin.yuna.typemap.model.TypeMap queryParams()Retrieves all query parameters from the currentHttpObject.- Returns:
- a
TypeMapcontaining all the query parameters.
-
containsQueryParam
Checks if a specific query parameter exists in theHttpObject.- Parameters:
key- the query parameter key to check.- Returns:
trueif the parameter exists,falseotherwise.
-
queryParam
Retrieves the value of a specified query parameter.- Parameters:
key- the key of the query parameter to retrieve.- Returns:
- the value of the parameter as a String, or
nullif the parameter does not exist.
-
pathMatch
Checks if the current
path()matches a specified expression. The expression may include:- Path variables enclosed in curly braces ({}), e.g., /users/{userId}.
- Asterisks (*) to match any single path segment, e.g., /users/*/profile
- Double asterisks (**) to match any number of path segments, e.g., /users/**..
Matching rules:
- Exact match: Each part of the path must match the corresponding part of the expression.
- Single asterisk (*): Matches any single path segment.
- Double asterisk (**): Matches zero or more path segments.
- Path variables: Captures the value of the segment and stores it in
pathParams().
- Parameters:
expression- the path expression to match against the current path.- Returns:
trueif the current path matches the expression,falseotherwise.
-
pathParams
public berlin.yuna.typemap.model.TypeMap pathParams()Retrieves a map of path parameters extracted from the URL.- Returns:
- a
TypeMapof path parameters.
-
pathParam
Retrieves the value of a specified path parameter.- Parameters:
key- the key of the path parameter.- Returns:
- the value of the path parameter, or
nullif it does not exist.
-
header
Retrieves the value of a specified header.- Parameters:
key- the key of the header to retrieve.- Returns:
- the value of the header, or
nullif the header is not found orkeyisnull.
-
containsHeader
Checks if a specified header exists in theHttpObject.- Parameters:
key- the key of the header to check.- Returns:
trueif the header exists,falseotherwise.
-
userAgent
Retrieves theHttpHeaders.USER_AGENTheader from theHttpObject.- Returns:
- the user agent string, or
nullif not set.
-
userAgent
Sets theHttpHeaders.USER_AGENTheader for theHttpObject.- Parameters:
userAgent- the user agent string to set.- Returns:
- this
HttpObjectto allow method chaining.
-
authToken
Parses and returns any authentication token found in theHttpHeaders.AUTHORIZATIONheader. Supports both 'Bearer' and 'Basic' authentication schemes.- Returns:
- token from the
authTokens()or null if noHttpHeaders.AUTHORIZATIONheader is present or the token cannot be parsed.
-
authToken
Parses and returns any authentication token found in theHttpHeaders.AUTHORIZATIONheader. Supports both 'Bearer' and 'Basic' authentication schemes.- Returns:
- token from the
authTokens()or null if noHttpHeaders.AUTHORIZATIONheader is present or the token cannot be parsed.
-
authTokens
Parses and returns any authentication token found in theHttpHeaders.AUTHORIZATIONheader. Supports both 'Bearer' and 'Basic' authentication schemes.- Returns:
- an array of strings, where the first element is the token or credentials,
or an empty array if no
HttpHeaders.AUTHORIZATIONheader is present or the token cannot be parsed.
-
exchange
Returns the associatedHttpExchangefor thisHttpObject.- Returns:
- the
HttpExchange, ornullif not available.
-
statusCode
Sets the HTTP status code for theHttpObject.- Parameters:
statusCode- the HTTP status code to set.- Returns:
- this
HttpObjectto allow method chaining.
-
statusCode
public int statusCode()Retrieves the current HTTP status code for theHttpObject.- Returns:
- the HTTP status code.
-
headerMap
public berlin.yuna.typemap.model.TypeMap headerMap()Returns the HTTP headers map.- Returns:
- a
TypeMapcontaining the headers.
-
computedHeaders
Constructs and returns a map of HTTP headers to be included in an HTTP response. This method ensures that essential headers are set, providing a sensible default for headers like Content-Encoding, Connection, Cache-Control, Accept-Encoding, Content-Type, Content-Length, and Date.
The method sets defaults for managing caching, connection persistence, and content encoding to optimize performance and compliance with HTTP standards. It also dynamically calculates content length and sets the current date and time in GMT format.
- Returns:
- A map where keys are header names and values are lists of string representing the header values.
This structure supports headers having multiple values.
Header Details: -
HttpHeaders.ACCEPT: Default "*\/*". -HttpHeaders.CACHE_CONTROL: Ensures fresh content by specifying "no-cache" and overrides with "max-age=0, private, must-revalidate" for more specific caching rules. -HttpHeaders.ACCEPT_ENCODING: Lists the acceptable encodings the server can handle, defaults to "gzip, deflate". -HttpHeaders.CONTENT_TYPE: Determined bycontentTypes()method to set the correct media type of the response. -HttpHeaders.CONTENT_LENGTH: Calculates the length of the response body to inform the client of the size of the response. -HttpHeaders.DATE: Sets the current date and time formatted according to RFC 7231.
-
sizeRequest
Sets the HTTP Range header to request only the first byte of the content. This method is typically used to determine the size of the content without downloading it entirely. The server should respond with the Content-Range header which includes the total size of the requested resource.- Returns:
- this
HttpObjectto allow method chaining.
-
sizeRequest
public boolean sizeRequest()Checks if the Range header has been set to request only the first byte of the content. This method is used to determine if the current request is a size request, which is typically used to fetch the size of the content without fully downloading it.- Returns:
- true if the Range header is set to "bytes=0-0", indicating a size request; false otherwise.
-
size
public long size()Calculates the size of the HTTP content. This method first attempts to retrieve the content size from the HTTP headers. It checks the
Content-Lengthheader for a direct size declaration. If not present, it tries to extract the size from theContent-Rangeheader, which is used in responses to range requests.If neither header is present or they don't contain valid size information, the method falls back to the length of the body, which is loaded into memory.
- Returns:
- the size of the content as a long. If the size cannot be determined from the headers, it returns the length of the body. If the headers are not set or are invalid, and the body is not loaded, it returns -1.
-
headerMap
Sets Http headers.- Parameters:
headers- the header keys and values.- Returns:
- this
HttpObjectfor method chaining.
-
headerMap
Sets Http headers.- Parameters:
headers- the header keys and values.- Returns:
- this
HttpObjectfor method chaining.
-
header
Adds or replaces a header in the HTTP headers map.- Parameters:
key- the header name.value- the header value.- Returns:
- this
HttpObjectfor method chaining.
-
queryParamsOf
-
bodyPublisher
- Specified by:
bodyPublisherin classHttpRequest
-
method
- Specified by:
methodin classHttpRequest
-
timeout
- Specified by:
timeoutin classHttpRequest
-
timeout
-
expectContinue
public boolean expectContinue()- Specified by:
expectContinuein classHttpRequest
-
uri
- Specified by:
uriin classHttpRequest
-
version
- Specified by:
versionin classHttpRequest
-
headers
- Specified by:
headersin classHttpRequest
-
response
Creates and returns a new instance ofHttpObject. This method is typically used to prepare a fresh response object in the context of HTTP handling. The new instance is completely independent of the current object, meaning it has no initialized fields from the current context.- Returns:
- a new, empty
HttpObject.
-
corsResponse
Creates and returns a new instance ofHttpObject. If CORS handling is requested, it delegates to the CORS response method.- Returns:
- a new
HttpObject, CORS-enabled.
-
response
Creates and returns a new instance ofHttpObject. If CORS handling is requested, it delegates to the CORS response method.- Parameters:
cors- if true, generates a CORS-enabled response.- Returns:
- a new
HttpObject, optionally CORS-enabled.
-
corsResponse
Creates and returns a new instance ofHttpObjectwith CORS handling. If the origin is not provided, it defaults to "*" (wildcard).- Parameters:
origin- comma separated list of whitelisted origins, or null for default.- Returns:
- a new
HttpObjectwith CORS handling.
-
corsResponse
Creates and returns a new instance ofHttpObjectwith CORS handling. Allows defining the origin and allowed methods.- Parameters:
origin- comma separated list of whitelisted origins, or null for default.methods- the allowed HTTP methods, or null to use the current method.- Returns:
- a new
HttpObjectwith CORS handling.
-
corsResponse
Creates and returns a new instance ofHttpObjectwith CORS handling. Allows defining the origin, methods, and headers.- Parameters:
origin- comma separated list of whitelisted origins, or null for default.methods- the allowed HTTP methods, or null to use the current method.headers- the allowed HTTP headers, or null to default headers.- Returns:
- a new
HttpObjectwith CORS handling.
-
corsResponse
Creates and returns a new instance ofHttpObjectwith CORS handling. Allows defining the origin, methods, headers, and max age for caching preflight responses.- Parameters:
origin- comma separated list of whitelisted origins, or null for default.methods- the allowed HTTP methods, or null to use the current method.headers- the allowed HTTP headers, or null to default headers.maxAge- the max age for caching preflight responses, or -1 for default (86400 seconds).- Returns:
- a new
HttpObjectwith CORS handling.
-
corsResponse
public HttpObject corsResponse(String origin, String methods, String headers, int maxAge, boolean credentials) Creates and returns a new instance ofHttpObjectwith CORS handling. Allows defining the origin, methods, headers, max age, and whether to allow credentials.- Parameters:
origin- comma separated list of whitelisted origins, or null for default.methods- the allowed HTTP methods, or null to use the current method.headers- the allowed HTTP headers, or null to default headers.maxAge- the max age for caching preflight responses, or -1 for default (86400 seconds).credentials- if true, enables Access-Control-Allow-Credentials header.- Returns:
- a new
HttpObjectwith CORS handling.
-
origin
Retrieves the origin from the current request. If the request does not specify an origin, it defaults to "*".- Returns:
- the origin of the request, or "*" if no origin is specified.
-
origin
Determines the value for theAccess-Control-Allow-Originheader.If credentials are allowed, the origin cannot be
"*". It prioritizes the providedorigin. If no valid origin is provided, it falls back to theORIGINorHOSTheaders from the request. Returns"null"if credentials are used and no origin is found, otherwise returns"*".- Parameters:
origin- comma separated list of whitelisted origins, or null for default.credentials- iftrue, prevents using"*"as the origin.- Returns:
- the appropriate origin, or
"null"if credentials are used and no origin is found.
-
origin
Sets the origin header for the currentHttpObject. If the provided origin is null or empty, the origin header is removed.- Parameters:
origin- the origin to set in the headers.- Returns:
- this
HttpObjectfor method chaining.
-
respond
Sends an HTTP response using the currentHttpObjectas the response context. This method utilizes the providedEventto carry the response back to the event handler or processor. TheHttpObjectis attached to the event as its response payload, allowing further processing or handling.- Parameters:
event- the event to which thisHttpObjectshould be attached as a response.- Returns:
- the event after attaching this
HttpObjectas a response, facilitating chaining and further manipulation.
-
send
Sends an HTTP request using the providedHttpObject. For async processing, use thesend(Context, Consumer)method.- Returns:
- the response as an
HttpObject
-
send
Sends an HTTP request using the providedHttpObject. If a response listener is provided, it processes the response asynchronously.- Parameters:
callback- an optional consumer to process the response asynchronously- Returns:
- the response as an
HttpObject
-
hasFailed
public boolean hasFailed()Checks if the HTTP response headers contain an entry indicating an exception or failure. This is typically used to determine if the HTTP operation encountered any errors that were captured and stored in the headers.- Returns:
- true if an exception or failure is indicated in the headers, false otherwise.
-
failure
Retrieves the failure exception from the HTTP headers, if present. This method directly accesses the headers to pull out aThrowableobject which represents the exception that was encountered during the HTTP transaction.- Returns:
- the
Throwablethat represents the failure, or null if no failure was recorded.
-
successOrElse
-
failure
Stores a failure exception within the HTTP headers. RFC 7807 To The Rescue! This method allows an exception to be attached to the HTTP object, potentially for logging purposes or for transmitting error information back to a client or server.- Parameters:
throwable- theThrowableexception to store in the headers.- Returns:
- this
HttpObjectto allow for method chaining.
-
isFrontendCall
public boolean isFrontendCall()Determines if theHttpObjectoriginates from a standard web browser based on theHttpHeaders.USER_AGENTheader. SeeUSER_AGENT_BROWSERSfor the list of browser identifiers.- Returns:
trueif theHttpHeaders.USER_AGENTheader contains identifiers typical of desktop browsers, otherwisefalse.
-
isMobileCall
public boolean isMobileCall()Determines if theHttpObjectoriginates from a mobile device based on theHttpHeaders.USER_AGENTheader. SeeUSER_AGENT_MOBILEfor the list of mobile identifiers.- Returns:
trueif theHttpHeaders.USER_AGENTheader contains identifiers typical of mobile devices, otherwisefalse.
-
host
Retrieves the host name from theHttpExchangeif available, otherwise extracts it from theHttpHeaders.HOSTheader.- Returns:
- the host name as a string, or
nullif it cannot be determined.
-
port
public int port()Retrieves the host port from theHttpExchangeif available, otherwise extracts it from theHttpHeaders.HOSTheader.- Returns:
- the port number as an integer, or -1 if it cannot be determined.
-
address
Retrieves theInetAddressfrom theHttpExchange.- Returns:
- an
InetAddressrepresenting the remote address, ornullif it is not available.
-
protocol
Retrieves the protocol used in theHttpExchange.- Returns:
- the protocol as a string, or
nullif the exchange is not available.
-
encoding
Retrieves the character set encoding from theHttpHeaders.CONTENT_TYPEheader.- Returns:
- a
Charsetobject representing the encoding specified in theHttpHeaders.CONTENT_TYPEheader, or theCharset.defaultCharset()if none is specified.
-
hasContentType
-
hasContentType
-
hasContentType
-
isMethodGet
public boolean isMethodGet() -
isMethodPost
public boolean isMethodPost() -
isMethodPut
public boolean isMethodPut() -
isMethodHead
public boolean isMethodHead() -
isMethodPatch
public boolean isMethodPatch() -
isMethodDelete
public boolean isMethodDelete() -
isMethodOptions
public boolean isMethodOptions() -
isMethodTrace
public boolean isMethodTrace() -
hasContentTypeJson
public boolean hasContentTypeJson() -
hasContentTypeXml
public boolean hasContentTypeXml() -
hasContentTypeXmlSoap
public boolean hasContentTypeXmlSoap() -
hasContentTypeOctetStream
public boolean hasContentTypeOctetStream() -
hasContentTypePdf
public boolean hasContentTypePdf() -
hasContentTypeFormUrlEncoded
public boolean hasContentTypeFormUrlEncoded() -
hasContentTypeMultiPartFormData
public boolean hasContentTypeMultiPartFormData() -
hasContentTypePlainText
public boolean hasContentTypePlainText() -
hasContentTypeHtml
public boolean hasContentTypeHtml() -
hasContentTypeJpeg
public boolean hasContentTypeJpeg() -
hasContentTypePng
public boolean hasContentTypePng() -
hasContentTypeGif
public boolean hasContentTypeGif() -
hasContentTypeMpeg
public boolean hasContentTypeMpeg() -
hasContentTypeMp4
public boolean hasContentTypeMp4() -
hasAcceptJson
public boolean hasAcceptJson() -
hasAcceptXml
public boolean hasAcceptXml() -
hasAcceptXmlSoap
public boolean hasAcceptXmlSoap() -
hasAcceptOctetStream
public boolean hasAcceptOctetStream() -
hasAcceptPdf
public boolean hasAcceptPdf() -
hasAcceptFormUrlEncoded
public boolean hasAcceptFormUrlEncoded() -
hasAcceptMultiPartFormData
public boolean hasAcceptMultiPartFormData() -
hasAcceptPlainText
public boolean hasAcceptPlainText() -
hasAcceptHtml
public boolean hasAcceptHtml() -
hasAcceptJpeg
public boolean hasAcceptJpeg() -
hasAcceptPng
public boolean hasAcceptPng() -
hasAcceptGif
public boolean hasAcceptGif() -
hasAcceptMpeg
public boolean hasAcceptMpeg() -
hasAcceptMp4
public boolean hasAcceptMp4() -
is1xxInformational
public boolean is1xxInformational() -
is2xxSuccessful
public boolean is2xxSuccessful() -
is3xxRedirection
public boolean is3xxRedirection() -
is4xxClientError
public boolean is4xxClientError() -
is5xxServerError
public boolean is5xxServerError() -
fromExchange
-
toString
-
guessContentType
-
splitHeaderValue
-
isMethod
-
convertHeaders
Converts a map of simple header values to aTypeMapof headers.- Parameters:
headers- a map containing header names and values.- Returns:
- a
TypeMaprepresenting the headers.
-
removeLast
-
isDeflateCompressed
public boolean isDeflateCompressed(byte[] body) -
isZipCompressed
public boolean isZipCompressed(byte[] body)
-