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
Buffers.
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
Nested ClassesModifier and TypeClassDescriptionstatic classThe 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
peerDecoderFields inherited from class org.jdrupes.httpcodec.protocols.http.HttpCodec
messageHeader -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionencode(Buffer in, ByteBuffer out, boolean endOfInput) Encodes a HTTP message.voidencode(HttpResponse messageHeader) Set a new HTTP message that is to be encoded.encoding()Returns the type of the messages encoded by this encoder.protected booleanForce close after body.protected HttpResponseEncoder.Result.FactoryReturns the result factory for this codec.protected voidstartMessage(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, setPendingLimitMethods inherited from class org.jdrupes.httpcodec.protocols.http.HttpCodec
bodyCharsetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jdrupes.httpcodec.Encoder
encode, header, setPeerDecoder
-
Constructor Details
-
HttpResponseEncoder
public HttpResponseEncoder()
-
-
Method Details
-
resultFactory
Description copied from class:HttpEncoderReturns the result factory for this codec.- Specified by:
resultFactoryin classHttpEncoder<HttpResponse,HttpRequest> - Returns:
- the factory
-
encoding
Description copied from interface:EncoderReturns the type of the messages encoded by this encoder.- Specified by:
encodingin interfaceEncoder<HttpResponse,HttpRequest> - Returns:
- the value
-
encode
Description copied from class:HttpEncoderSet a new HTTP message that is to be encoded.- Specified by:
encodein interfaceEncoder<HttpResponse,HttpRequest> - Overrides:
encodein classHttpEncoder<HttpResponse,HttpRequest> - Parameters:
messageHeader- the response
-
encode
Description copied from class:HttpEncoderEncodes a HTTP message.- Specified by:
encodein interfaceEncoder<HttpResponse,HttpRequest> - Overrides:
encodein 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:HttpEncoderWrites 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:
startMessagein 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:HttpEncoderForce close after body.Used to override the header driven behavior for HTTP/1.0 responses.
- Overrides:
forceCloseAfterBodyin classHttpEncoder<HttpResponse,HttpRequest> - Returns:
- true, if forced
-