Class HttpResponseEncoder
java.lang.Object
org.jdrupes.httpcodec.protocols.http.HttpCodec<T>
org.jdrupes.httpcodec.protocols.http.HttpEncoder<HttpResponse,HttpRequest>
org.jdrupes.httpcodec.protocols.http.server.HttpResponseEncoder
- All Implemented Interfaces:
Codec
,Encoder<HttpResponse,
HttpRequest>
public class HttpResponseEncoder
extends HttpEncoder<HttpResponse,HttpRequest>
implements Encoder<HttpResponse,HttpRequest>
An encoder for HTTP responses.
It accepts a header and optional
payload data end encodes it into a sequence of
Buffer
s.
Headers
Date
The encoder automatically adds a Date
header as specified
in RFC 7231, Section 7.1.1.2.
Any existing Date
header will be overwritten.
Expires
If the protocol is HTTP 1.0 and the response includes a Cache-Control
header field with a max-age
directive, an Expires
header field
with the same information is generated (see
RFC 7234, Section 5.3).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The result from encoding a response.Nested classes/interfaces inherited from interface org.jdrupes.httpcodec.Codec
Codec.ProtocolSwitchResult
-
Field Summary
Fields inherited from class org.jdrupes.httpcodec.protocols.http.HttpEncoder
peerDecoder
Fields inherited from class org.jdrupes.httpcodec.protocols.http.HttpCodec
messageHeader
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionencode
(Buffer in, ByteBuffer out, boolean endOfInput) Encodes a HTTP message.void
encode
(HttpResponse messageHeader) Set a new HTTP message that is to be encoded.encoding()
Returns the type of the messages encoded by this encoder.protected boolean
Force close after body.protected HttpResponseEncoder.Result.Factory
Returns the result factory for this codec.protected void
startMessage
(HttpResponse response, Writer writer) Writes the first line of the message (including the terminating CRLF).Methods inherited from class org.jdrupes.httpcodec.protocols.http.HttpEncoder
header, isClosed, pendingLimit, setPeerDecoder, setPendingLimit
Methods inherited from class org.jdrupes.httpcodec.protocols.http.HttpCodec
bodyCharset
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jdrupes.httpcodec.Encoder
encode, header, setPeerDecoder
-
Constructor Details
-
HttpResponseEncoder
public HttpResponseEncoder()
-
-
Method Details
-
resultFactory
Description copied from class:HttpEncoder
Returns the result factory for this codec.- Specified by:
resultFactory
in classHttpEncoder<HttpResponse,
HttpRequest> - Returns:
- the factory
-
encoding
Description copied from interface:Encoder
Returns the type of the messages encoded by this encoder.- Specified by:
encoding
in interfaceEncoder<HttpResponse,
HttpRequest> - Returns:
- the value
-
encode
Description copied from class:HttpEncoder
Set a new HTTP message that is to be encoded.- Specified by:
encode
in interfaceEncoder<HttpResponse,
HttpRequest> - Overrides:
encode
in classHttpEncoder<HttpResponse,
HttpRequest> - Parameters:
messageHeader
- the response
-
encode
Description copied from class:HttpEncoder
Encodes a HTTP message.- Specified by:
encode
in interfaceEncoder<HttpResponse,
HttpRequest> - Overrides:
encode
in classHttpEncoder<HttpResponse,
HttpRequest> - Parameters:
in
- the body dataout
- the buffer to which data is writtenendOfInput
- true if there is no input left beyond the data currently in the in buffer (indicates end of body or no body at all)- Returns:
- the result
-
startMessage
Description copied from class:HttpEncoder
Writes the first line of the message (including the terminating CRLF).Must be provided by the derived class because the first line depends on whether a request or response is encoded.
- Specified by:
startMessage
in classHttpEncoder<HttpResponse,
HttpRequest> - Parameters:
response
- the message header to encode (seeHttpEncoder.encode(HttpMessageHeader)
writer
- the Writer to use for writing- Throws:
IOException
- if an I/O error occurs
-
forceCloseAfterBody
Description copied from class:HttpEncoder
Force close after body.Used to override the header driven behavior for HTTP/1.0 responses.
- Overrides:
forceCloseAfterBody
in classHttpEncoder<HttpResponse,
HttpRequest> - Returns:
- true, if forced
-