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 StringThe HTTP request authority.protected HTTPResponderTheHTTPResponderto use in therespondmethods.protected StringThe HTTP request method.protected StringThe HTTP request path.protected StringThe HTTP request scheme.Fields inherited from class org.omegazero.http.common.HTTPMessage
chunkedTransfer, createdTime, httpVersion, locked, otherFields inherited from class org.omegazero.http.common.HTTPHeaderContainer
headerFieldsFields 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, ornullif thisHTTPMessagedoes not contain an authority component.Returns theHTTPResponderset usingsetHttpResponder(HTTPResponder)used inrespond(HTTPResponseData)and similar methods.Returns the HTTP request method of thisHTTPRequest.getOther()Returns the otherHTTPMessageof the HTTP message exchange thisHTTPMessageis part of.getPath()Returns the HTTP request path (URI component) of thisHTTPRequest.Returns the HTTP request scheme (URI component) of thisHTTPRequest.booleanGenerates a HTTP/1-style request line of the form [method] [requestURI] HTTP/[version number].Generates the request URI of thisHTTPRequest.voidResponds to thisHTTPRequestusing anHTTPResponderset for this object.voidrespond(HTTPResponseData response) Responds to thisHTTPRequestusing anHTTPResponderset for this object.voidsetAuthority(String authority) Sets the HTTP authority (URI component) of thisHTTPRequest.voidsetHttpResponder(HTTPResponder httpResponder) Sets aHTTPResponderused inrespond(HTTPResponseData)and similar methods.voidSets the HTTP request method of thisHTTPRequest.voidSets the HTTP path (URI component) of thisHTTPRequest.voidSets the HTTP scheme (URI component) of thisHTTPRequest.Methods inherited from class org.omegazero.http.common.HTTPMessage
checkLocked, getCreatedTime, getHttpVersion, isChunkedTransfer, isLocked, lock, setChunkedTransfer, setHttpVersion, setOtherMethods 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, toStringMethods inherited from class org.omegazero.common.util.SimpleAttachmentContainer
getAttachment, hasAttachment, removeAttachment, setAttachmentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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
TheHTTPResponderto use in therespondmethods.
-
-
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
HTTPHeaderContainerwill 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 benullif neither is providedpath- The request URL path componentversion- The HTTP versionheaders- The HTTP headers, ornullto create an empty set of headers
-
HTTPRequest
Copies the givenHTTPRequest.- Parameters:
request- TheHTTPRequestto 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, ornullif thisHTTPMessagedoes 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 thisHTTPMessageis locked- See Also:
-
setScheme
Sets the HTTP scheme (URI component) of thisHTTPRequest.- Parameters:
scheme- The new HTTP request scheme- Throws:
IllegalStateException- If thisHTTPMessageis locked- See Also:
-
setAuthority
Sets the HTTP authority (URI component) of thisHTTPRequest.- Parameters:
authority- The new HTTP request authority- Throws:
IllegalStateException- If thisHTTPMessageis locked- See Also:
-
setPath
Sets the HTTP path (URI component) of thisHTTPRequest.- Parameters:
path- The new HTTP request path- Throws:
IllegalStateException- If thisHTTPMessageis locked- See Also:
-
getHttpResponder
Returns theHTTPResponderset usingsetHttpResponder(HTTPResponder)used inrespond(HTTPResponseData)and similar methods.- Returns:
- The
HTTPResponder
-
setHttpResponder
Sets aHTTPResponderused inrespond(HTTPResponseData)and similar methods.- Parameters:
httpResponder- TheHTTPResponder- Throws:
IllegalStateException- If thisHTTPMessageis locked
-
hasResponse
public boolean hasResponse()- Returns:
trueif thisHTTPRequesthas a response
-
getOther
Description copied from class:HTTPMessageReturns the otherHTTPMessageof the HTTP message exchange thisHTTPMessageis part of. This may benull.For example, for
HTTPRequests, this would be the response of the request, and vice versa.- Overrides:
getOtherin classHTTPMessage- Returns:
- The other
HTTPMessageinvolved in the HTTP message exchange
-
respond
Responds to thisHTTPRequestusing anHTTPResponderset for this object.- Parameters:
response- The response- Throws:
IllegalStateException- If noHTTPResponderis set- See Also:
-
respond
Responds to thisHTTPRequestusing anHTTPResponderset 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 noHTTPResponderis set- See Also:
-