Package org.omegazero.http.common
Class HTTPRequest
java.lang.Object
org.omegazero.common.util.SimpleAttachmentContainer
org.omegazero.http.common.HTTPHeaderContainer
org.omegazero.http.common.HTTPMessage
org.omegazero.http.common.HTTPRequest
- All Implemented Interfaces:
Serializable
,org.omegazero.common.util.AttachmentContainer
Represents a HTTP request, a specific type of
HTTPMessage
.- Since:
- 1.2.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
The HTTP request authority.protected HTTPResponder
TheHTTPResponder
to use in therespond
methods.protected String
The HTTP request method.protected String
The HTTP request path.protected String
The HTTP request scheme.Fields inherited from class org.omegazero.http.common.HTTPMessage
chunkedTransfer, createdTime, httpVersion, locked, other
Fields inherited from class org.omegazero.http.common.HTTPHeaderContainer
headerFields
Fields inherited from class org.omegazero.common.util.SimpleAttachmentContainer
attachments
-
Constructor Summary
ConstructorsConstructorDescriptionHTTPRequest
(String method, String scheme, String authority, String path, String version, HTTPHeaderContainer headers) Creates a newHTTPRequest
.HTTPRequest
(HTTPRequest request) Copies the givenHTTPRequest
. -
Method Summary
Modifier and TypeMethodDescriptionReturns the HTTP request authority (URI component) of thisHTTPRequest
, ornull
if thisHTTPMessage
does not contain an authority component.Returns theHTTPResponder
set usingsetHttpResponder(HTTPResponder)
used inrespond(HTTPResponseData)
and similar methods.Returns the HTTP request method of thisHTTPRequest
.getOther()
Returns the otherHTTPMessage
of the HTTP message exchange thisHTTPMessage
is part of.getPath()
Returns the HTTP request path (URI component) of thisHTTPRequest
.Returns the HTTP request scheme (URI component) of thisHTTPRequest
.boolean
Generates a HTTP/1-style request line of the form [method] [requestURI] HTTP/[version number].Generates the request URI of thisHTTPRequest
.void
Responds to thisHTTPRequest
using anHTTPResponder
set for this object.void
respond
(HTTPResponseData response) Responds to thisHTTPRequest
using anHTTPResponder
set for this object.void
setAuthority
(String authority) Sets the HTTP authority (URI component) of thisHTTPRequest
.void
setHttpResponder
(HTTPResponder httpResponder) Sets aHTTPResponder
used inrespond(HTTPResponseData)
and similar methods.void
Sets the HTTP request method of thisHTTPRequest
.void
Sets the HTTP path (URI component) of thisHTTPRequest
.void
Sets the HTTP scheme (URI component) of thisHTTPRequest
.Methods inherited from class org.omegazero.http.common.HTTPMessage
checkLocked, getCreatedTime, getHttpVersion, isChunkedTransfer, isLocked, lock, setChunkedTransfer, setHttpVersion, setOther
Methods inherited from class org.omegazero.http.common.HTTPHeaderContainer
addHeader, addHeader, appendHeader, appendHeader, appendHeader, deleteHeader, deleteHeader, editHeader, extractHeader, extractHeaders, fromLegacy, getHeader, getHeader, getHeader, getHeader, getHeaderCount, headerExists, headerIterator, headerNameCount, headerNameSet, headers, headerSet, setHeader, toString
Methods inherited from class org.omegazero.common.util.SimpleAttachmentContainer
getAttachment, hasAttachment, removeAttachment, setAttachment
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.omegazero.common.util.AttachmentContainer
requireAttachment
-
Field Details
-
method
The HTTP request method. -
scheme
The HTTP request scheme. -
authority
The HTTP request authority. -
path
The HTTP request path. -
httpResponder
TheHTTPResponder
to use in therespond
methods.
-
-
Constructor Details
-
HTTPRequest
public HTTPRequest(String method, String scheme, String authority, String path, String version, HTTPHeaderContainer headers) Creates a newHTTPRequest
.Note that no deep copy of the headers will be created, meaning changes made to the given
HTTPHeaderContainer
will reflect on thisHTTPRequest
.- Parameters:
method
- The request methodscheme
- The request URL scheme (e.g. "http")authority
- The request URL authority or, if not provided, the value of the "Host" header (e.g. "example.com"). May benull
if neither is providedpath
- The request URL path componentversion
- The HTTP versionheaders
- The HTTP headers, ornull
to create an empty set of headers
-
HTTPRequest
Copies the givenHTTPRequest
.- Parameters:
request
- TheHTTPRequest
to copy from- See Also:
-
-
Method Details
-
requestURI
Generates the request URI of thisHTTPRequest
. This always contains the URL scheme and authority component, and the path component if the path is not equal to "*
".- Returns:
- The request URI of this
HTTPRequest
-
requestLine
Generates a HTTP/1-style request line of the form [method] [requestURI] HTTP/[version number].- Returns:
- A request line
-
getMethod
Returns the HTTP request method of thisHTTPRequest
.- Returns:
- The HTTP request method
- See Also:
-
getScheme
Returns the HTTP request scheme (URI component) of thisHTTPRequest
.- Returns:
- The HTTP request scheme
- See Also:
-
getAuthority
Returns the HTTP request authority (URI component) of thisHTTPRequest
, ornull
if thisHTTPMessage
does not contain an authority component.- Returns:
- The HTTP request authority
- See Also:
-
getPath
Returns the HTTP request path (URI component) of thisHTTPRequest
.- Returns:
- The HTTP request path
- See Also:
-
setMethod
Sets the HTTP request method of thisHTTPRequest
.- Parameters:
method
- The new HTTP request method- Throws:
IllegalStateException
- If thisHTTPMessage
is locked- See Also:
-
setScheme
Sets the HTTP scheme (URI component) of thisHTTPRequest
.- Parameters:
scheme
- The new HTTP request scheme- Throws:
IllegalStateException
- If thisHTTPMessage
is locked- See Also:
-
setAuthority
Sets the HTTP authority (URI component) of thisHTTPRequest
.- Parameters:
authority
- The new HTTP request authority- Throws:
IllegalStateException
- If thisHTTPMessage
is locked- See Also:
-
setPath
Sets the HTTP path (URI component) of thisHTTPRequest
.- Parameters:
path
- The new HTTP request path- Throws:
IllegalStateException
- If thisHTTPMessage
is locked- See Also:
-
getHttpResponder
Returns theHTTPResponder
set usingsetHttpResponder(HTTPResponder)
used inrespond(HTTPResponseData)
and similar methods.- Returns:
- The
HTTPResponder
-
setHttpResponder
Sets aHTTPResponder
used inrespond(HTTPResponseData)
and similar methods.- Parameters:
httpResponder
- TheHTTPResponder
- Throws:
IllegalStateException
- If thisHTTPMessage
is locked
-
hasResponse
public boolean hasResponse()- Returns:
true
if thisHTTPRequest
has a response
-
getOther
Description copied from class:HTTPMessage
Returns the otherHTTPMessage
of the HTTP message exchange thisHTTPMessage
is part of. This may benull
.For example, for
HTTPRequest
s, this would be the response of the request, and vice versa.- Overrides:
getOther
in classHTTPMessage
- Returns:
- The other
HTTPMessage
involved in the HTTP message exchange
-
respond
Responds to thisHTTPRequest
using anHTTPResponder
set for this object.- Parameters:
response
- The response- Throws:
IllegalStateException
- If noHTTPResponder
is set- See Also:
-
respond
Responds to thisHTTPRequest
using anHTTPResponder
set for this object.- Parameters:
status
- The status code of the responsedata
- The data to send in the responseheaders
- Headers to send in the response- Throws:
IllegalStateException
- If noHTTPResponder
is set- See Also:
-