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, otherFields inherited from class org.omegazero.http.common.HTTPHeaderContainer
headerFieldsFields 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 otherHTTPMessageof the HTTP message exchange thisHTTPMessageis part of.intReturns the HTTP response status code of thisHTTPResponse.booleanDetermines whether thisHTTPResponsehas a response body if initiated by the given request.static booleanhasResponseBody(int status) Determines whether responses with the given status code should have a response body.booleanhasResponseBody(HTTPRequest request) Determines whether thisHTTPResponsehas a response body if initiated by the given request.booleanDetermines whether thisHTTPResponseis an intermediate message, meaning it is followed up by anotherHTTPResponseto complete the HTTP exchange or it has some other special meaning.Generates a HTTP/1-style response line of the form HTTP/[version] [status].voidsetStatus(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, 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
-
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
HTTPHeaderContainerwill reflect on thisHTTPResponse.- Parameters:
status- The HTTP response status codeversion- The HTTP versionheaders- The HTTP headers, ornullto create an empty set of headers
-
HTTPResponse
Copies the givenHTTPResponse.- Parameters:
response- TheHTTPResponseto 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 thisHTTPMessageis locked- See Also:
-
isIntermediateMessage
public boolean isIntermediateMessage()Determines whether thisHTTPResponseis an intermediate message, meaning it is followed up by anotherHTTPResponseto complete the HTTP exchange or it has some other special meaning.This applies to responses with 1xx response codes.
- Returns:
trueif thisHTTPResponseis an intermediate message
-
hasResponseBody
public boolean hasResponseBody()Determines whether thisHTTPResponsehas a response body if initiated by the given request. This istrueif 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:
trueif thisHTTPResponseshould contain a response body- See Also:
-
hasResponseBody
Determines whether thisHTTPResponsehas a response body if initiated by the given request. This istrueif 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:
trueif thisHTTPResponseshould contain a response body if initiated by the given request- See Also:
-
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
-
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:
trueif a response with the given status code should have a response body- See Also:
-