Package org.omegazero.http.common
Class HTTPResponse
java.lang.Object
org.omegazero.common.util.SimpleAttachmentContainer
org.omegazero.http.common.HTTPHeaderContainer
org.omegazero.http.common.HTTPMessage
org.omegazero.http.common.HTTPResponse
- All Implemented Interfaces:
Serializable
,org.omegazero.common.util.AttachmentContainer
Represents a HTTP response, a specific type of
HTTPMessage
.- Since:
- 1.2.1
- See Also:
-
Field Summary
FieldsFields 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
ConstructorsConstructorDescriptionHTTPResponse
(int status, String version, HTTPHeaderContainer headers) Creates a newHTTPResponse
.HTTPResponse
(HTTPResponse response) Copies the givenHTTPResponse
. -
Method Summary
Modifier and TypeMethodDescriptiongetOther()
Returns the otherHTTPMessage
of the HTTP message exchange thisHTTPMessage
is part of.int
Returns the HTTP response status code of thisHTTPResponse
.boolean
Determines whether thisHTTPResponse
has a response body if initiated by the given request.static boolean
hasResponseBody
(int status) Determines whether responses with the given status code should have a response body.boolean
hasResponseBody
(HTTPRequest request) Determines whether thisHTTPResponse
has a response body if initiated by the given request.boolean
Determines whether thisHTTPResponse
is an intermediate message, meaning it is followed up by anotherHTTPResponse
to complete the HTTP exchange or it has some other special meaning.Generates a HTTP/1-style response line of the form HTTP/[version] [status].void
setStatus
(int status) Sets the HTTP response status code of thisHTTPResponse
.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
-
status
protected int statusThe HTTP response status.
-
-
Constructor Details
-
HTTPResponse
Creates a newHTTPResponse
.Note that no deep copy of the headers will be created, meaning changes made to the given
HTTPHeaderContainer
will reflect on thisHTTPResponse
.- Parameters:
status
- The HTTP response status codeversion
- The HTTP versionheaders
- The HTTP headers, ornull
to create an empty set of headers
-
HTTPResponse
Copies the givenHTTPResponse
.- Parameters:
response
- TheHTTPResponse
to copy from- See Also:
-
-
Method Details
-
responseLine
Generates a HTTP/1-style response line of the form HTTP/[version] [status].- Returns:
- A response line
-
getStatus
public int getStatus()Returns the HTTP response status code of thisHTTPResponse
.- Returns:
- The HTTP response status code
- See Also:
-
setStatus
public void setStatus(int status) Sets the HTTP response status code of thisHTTPResponse
.- Parameters:
status
- The new HTTP response status code- Throws:
IllegalStateException
- If thisHTTPMessage
is locked- See Also:
-
isIntermediateMessage
public boolean isIntermediateMessage()Determines whether thisHTTPResponse
is an intermediate message, meaning it is followed up by anotherHTTPResponse
to complete the HTTP exchange or it has some other special meaning.This applies to responses with 1xx response codes.
- Returns:
true
if thisHTTPResponse
is an intermediate message
-
hasResponseBody
public boolean hasResponseBody()Determines whether thisHTTPResponse
has a response body if initiated by the given request. This istrue
if this response's status has a response body, and the request that initiated this response did not use the HEAD method, or the CONNECT method with a 2xx response status.A call to this method is equivalent to a call to
response.
hasResponseBody
(response.getOther
());- Returns:
true
if thisHTTPResponse
should contain a response body- See Also:
-
hasResponseBody
Determines whether thisHTTPResponse
has a response body if initiated by the given request. This istrue
if this response's status has a response body, and the given request did not use the HEAD method, or the CONNECT method with a 2xx response status.- Parameters:
request
- The request to check with. May benull
, in which case only the response status is checked- Returns:
true
if thisHTTPResponse
should contain a response body if initiated by the given request- See Also:
-
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
-
hasResponseBody
public static boolean hasResponseBody(int status) Determines whether responses with the given status code should have a response body. Responses with statuses 1xx, 204, and 304 do not have a response body.- Parameters:
status
- A HTTP status code- Returns:
true
if a response with the given status code should have a response body- See Also:
-