Class HttpRequest
java.lang.Object
org.jdrupes.httpcodec.protocols.http.HttpMessageHeader
org.jdrupes.httpcodec.protocols.http.HttpRequest
- All Implemented Interfaces:
MessageHeader
Represents an HTTP request header.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHttpRequest
(String method, URI requestUri, HttpConstants.HttpProtocol httpProtocol, boolean hasPayload) Creates a new request with basic data. -
Method Summary
Modifier and TypeMethodDescriptionhost()
method()
Return the method.int
port()
Short for invokingqueryData(Charset)
with UTF-8 as charset.Returns the decoded query data from the request URI.Return the URI of the requested resource.response()
Returns the prepared response.<T> HttpRequest
Sets a header field for the message.Sets a header field for the message.setHasPayload
(boolean hasPayload) Set the flag that indicates whether this header is followed by a body.setHostAndPort
(String host, int port) Set the host and port attributes.setResponse
(HttpResponse response) Associates the request with a response.toString()
Methods inherited from class org.jdrupes.httpcodec.protocols.http.HttpMessageHeader
clearHeaders, computeIfAbsent, computeIfAbsent, fields, findField, findStringValue, findValue, hasPayload, isFinal, protocol, removeField
-
Field Details
-
ASTERISK_REQUEST
-
-
Constructor Details
-
HttpRequest
public HttpRequest(String method, URI requestUri, HttpConstants.HttpProtocol httpProtocol, boolean hasPayload) Creates a new request with basic data.The
host()
andport()
values are initialized with the values from therequestUri
.- Parameters:
method
- the methodrequestUri
- the requested resourcehttpProtocol
- the HTTP protocol versionhasPayload
- indicates that the message has a payload body
-
-
Method Details
-
setField
Description copied from class:HttpMessageHeader
Sets a header field for the message.- Overrides:
setField
in classHttpMessageHeader
- Parameters:
value
- the header field’s value- Returns:
- the message header for easy chaining
-
setField
Description copied from class:HttpMessageHeader
Sets a header field for the message.The converter for the field is looked up using
HttpField.lookupConverter(String)
.- Overrides:
setField
in classHttpMessageHeader
- Type Parameters:
T
- the type of the value- Parameters:
name
- the field namevalue
- the header field’s value- Returns:
- the message header for easy chaining
-
setHasPayload
Description copied from class:HttpMessageHeader
Set the flag that indicates whether this header is followed by a body.- Overrides:
setHasPayload
in classHttpMessageHeader
- Parameters:
hasPayload
- new value- Returns:
- the message for easy chaining
-
method
Return the method.- Returns:
- the method
-
requestUri
Return the URI of the requested resource.- Returns:
- the requestUri
-
setHostAndPort
Set the host and port attributes.- Parameters:
host
- the hostport
- the port- Returns:
- the request for easy chaining
-
host
- Returns:
- the host
-
port
- Returns:
- the port
-
setResponse
Associates the request with a response.This method is invoked by the request decoder that initializes the response with basic information that can be derived from the request (e.g. by default the HTTP version is copied). The status code of the preliminary response is 501 “Not implemented”.
Although not strictly required, users of the API are encouraged to modify this prepared request and use it when building the response.
- Parameters:
response
- the prepared response- Returns:
- the request for easy chaining
-
response
Returns the prepared response.- Returns:
- the prepared response
- See Also:
-
queryData
Returns the decoded query data from the request URI.The result is a lazily created (and cached) unmodifiable map.
- Parameters:
charset
- the charset to use for decoding- Returns:
- the data
- Throws:
UnsupportedEncodingException
- the unsupported encoding exception
-
queryData
Short for invokingqueryData(Charset)
with UTF-8 as charset.- Returns:
- the map
-
toString
-