Class HttpResponse
java.lang.Object
org.jdrupes.httpcodec.protocols.http.HttpMessageHeader
org.jdrupes.httpcodec.protocols.http.HttpResponse
- All Implemented Interfaces:
MessageHeader
Represents an HTTP response header.
-
Constructor Summary
ConstructorDescriptionHttpResponse
(HttpConstants.HttpProtocol protocol, int statusCode, String reasonPhrase, boolean hasPayload) HttpResponse
(HttpConstants.HttpProtocol protocol, HttpConstants.HttpStatus status, boolean hasPayload) -
Method Summary
Modifier and TypeMethodDescriptionstatic MediaType
contentType
(URI requestUri) Derives a media type from the given URI.request()
Returns the request that this response responds to.setContentLength
(long length) A convenience method for setting the “Content-Length” header.setContentType
(String type, String subtype) Convenience method for setting the “Content-Type” header from the given values.setContentType
(String type, String subtype, String charset) A convenience method for setting the “Content-Type” header (usually of type “text”) together with its charset parameter.setContentType
(URI requestUri) Convenience method for setting the “Content-Type” header using the path information of the given request.setContentType
(MediaType mediaType) Convenience method for setting the “Content-Type” header using the given media type.<T> HttpResponse
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.setReasonPhrase
(String reasonPhrase) setRequest
(HttpRequest request) Associates the response with the request that it responds to.setStatus
(HttpConstants.HttpStatus status) Sets both status code and reason phrase from the given http status value.setStatusCode
(int statusCode) int
Methods inherited from class org.jdrupes.httpcodec.protocols.http.HttpMessageHeader
clearHeaders, computeIfAbsent, computeIfAbsent, fields, findField, findStringValue, findValue, hasPayload, isFinal, protocol, removeField
-
Constructor Details
-
HttpResponse
public HttpResponse(HttpConstants.HttpProtocol protocol, HttpConstants.HttpStatus status, boolean hasPayload) -
HttpResponse
public HttpResponse(HttpConstants.HttpProtocol protocol, int statusCode, String reasonPhrase, boolean hasPayload)
-
-
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
-
statusCode
- Returns:
- the responseCode
-
setStatusCode
- Parameters:
statusCode
- the responseCode to set- Returns:
- the response for easy chaining
-
reasonPhrase
- Returns:
- the reason phrase
-
setReasonPhrase
- Parameters:
reasonPhrase
- the reason phrase to set- Returns:
- the response for easy chaining
-
setStatus
Sets both status code and reason phrase from the given http status value.- Parameters:
status
- the status value- Returns:
- the response for easy chaining
-
setContentType
Convenience method for setting the “Content-Type” header using the given media type.Also sets the “has payload” flag.
- Parameters:
mediaType
- the media type- Returns:
- the response for easy chaining
-
setContentType
Convenience method for setting the “Content-Type” header from the given values.Also sets the “has payload” flag.
- Parameters:
type
- the typesubtype
- the subtype- Returns:
- the response for easy chaining
- Throws:
ParseException
- if the values cannot be parsed
-
setContentType
public HttpResponse setContentType(String type, String subtype, String charset) throws ParseException A convenience method for setting the “Content-Type” header (usually of type “text”) together with its charset parameter.Also sets the “has payload” flag.
- Parameters:
type
- the typesubtype
- the subtypecharset
- the charset- Returns:
- the response for easy chaining
- Throws:
ParseException
- if the values cannot be parsed
-
setContentType
Convenience method for setting the “Content-Type” header using the path information of the given request.Also sets the “has payload” flag.
- Parameters:
requestUri
- the requested resource- Returns:
- the response for easy chaining
-
contentType
Derives a media type from the given URI.- Parameters:
requestUri
- the uri- Returns:
- the media type
-
setContentLength
A convenience method for setting the “Content-Length” header.- Parameters:
length
- the length- Returns:
- the response for easy chaining
-
setRequest
Associates the response with the request that it responds to.This method is invoked by the request decoder when it creates the prepared response for a request. The relationship with the request is required because information from the request headers may be needed when encoding the response.
- Parameters:
request
- the request- Returns:
- the response for easy chaining
- See Also:
-
request
Returns the request that this response responds to.- Returns:
- the request
- See Also:
-