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
-
Constructor Summary
ConstructorDescriptionHttpRequest
(String method, URI requestUri, HttpConstants.HttpProtocol httpProtocol, boolean hasPayload) Creates a new request with basic data. -
Method Summary
Modifier and TypeMethodDescriptionhost()
Host.method()
Return the method.int
port()
Port.Short for invokingqueryData(Charset)
with UTF-8 as charset.Returns the decoded query data from the request URI.static URI
replaceQuery
(URI uri, String query) Updates the query part of an 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.setQueryData
(Map<String, List<String>> data) Updates the query part of the request URI, using UTF-8 to encode the query keys and values.Updates the query part of the request URI.setResponse
(HttpResponse response) Associates the request with a response.setSimpleQueryData
(Map<String, String> data) Updates the query part of the request URI, using UTF-8 to encode the query keys and values.setSimpleQueryData
(Map<String, String> data, Charset charset) Updates the query part of the request URI.static String
simpleWwwFormUrlencode
(Map<String, String> data) Www-form-urlencodes the given data, using UTF-8 to encode keys and values.static String
simpleWwwFormUrlencode
(Map<String, String> data, Charset charset) Www-form-urlencodes the given data, using the given charset to encode keys and values.toString()
static String
wwwFormUrlencode
(Map<String, List<String>> data) Www-form-urlencodes the given data, using UTF-8 to encode keys and values.static String
Www-form-urlencodes the given data, using the given charset to encode keys and values.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
The Constant 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
Host.- Returns:
- the host
-
port
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
-
replaceQuery
Updates the query part of an URI.- Parameters:
uri
- the uriquery
- the query in raw form, i.e. as it should appear in the request- Returns:
- the new URI
-
setSimpleQueryData
Updates the query part of the request URI.- Parameters:
data
- the datacharset
- the charset to use for encoding keys and values- Returns:
- the http request
-
setSimpleQueryData
Updates the query part of the request URI, using UTF-8 to encode the query keys and values.- Parameters:
data
- the data- Returns:
- the http request
-
setQueryData
Updates the query part of the request URI.- Parameters:
data
- the datacharset
- the charset to use for encoding keys and values- Returns:
- the http request
-
setQueryData
Updates the query part of the request URI, using UTF-8 to encode the query keys and values.- Parameters:
data
- the data- Returns:
- the http request
-
toString
-
simpleWwwFormUrlencode
Www-form-urlencodes the given data, using the given charset to encode keys and values.- Parameters:
data
- the datacharset
- the charset to use for encoding keys and values- Returns:
- the string
-
simpleWwwFormUrlencode
Www-form-urlencodes the given data, using UTF-8 to encode keys and values.- Parameters:
data
- the datacharset
- the charset- Returns:
- the string
-
wwwFormUrlencode
Www-form-urlencodes the given data, using the given charset to encode keys and values.- Parameters:
data
- the datacharset
- the charset to use for encoding keys and values- Returns:
- the string
-
wwwFormUrlencode
Www-form-urlencodes the given data, using UTF-8 to encode keys and values.- Parameters:
data
- the datacharset
- the charset- Returns:
- the string
-