Class HttpEncoder<T extends HttpMessageHeader,D extends HttpMessageHeader>
- Type Parameters:
T- the type of the message header to be encodedD- the type of the message header decoded by the peer decoder
- Direct Known Subclasses:
HttpRequestEncoder,HttpResponseEncoder
The class can be used as base class for both a request and a response encoder.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResults fromHttpEncoderprovide no additional information compared toCodec.Result.Nested classes/interfaces inherited from interface org.jdrupes.httpcodec.Codec
Codec.ProtocolSwitchResult -
Field Summary
FieldsFields 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.voidSet a new HTTP message that is to be encoded.protected booleanForce close after body.header()Returns the last message (header) encoded.booleanisClosed()Returns true if the encoder does not accept further input because the processed data indicated that the connection has been or is to be closed.intReturns the limit for pending body bytes.protected abstract HttpEncoder.Result.FactoryReturns the result factory for this codec.setPeerDecoder(Decoder<D, T> decoder) Sets the peer decoder.voidsetPendingLimit(int pendingLimit) Sets the limit for the pending body bytes.protected abstract voidstartMessage(T messageHeader, Writer writer) Writes the first line of the message (including the terminating CRLF).Methods inherited from class org.jdrupes.httpcodec.protocols.http.HttpCodec
bodyCharset
-
Field Details
-
peerDecoder
-
-
Constructor Details
-
HttpEncoder
public HttpEncoder()Creates a new encoder.
-
-
Method Details
-
setPeerDecoder
Description copied from interface:EncoderSets the peer decoder.Some decoder implementations need to know the state of the decoder or the last decoded message.
- Specified by:
setPeerDecoderin interfaceEncoder<T extends HttpMessageHeader,D extends HttpMessageHeader> - Parameters:
decoder- the decoder- Returns:
- the encoder
-
resultFactory
Returns the result factory for this codec.- Returns:
- the factory
-
pendingLimit
Returns the limit for pending body bytes.If the protocol is HTTP/1.0 and the message has a body but no “Content-Length” header, the only (unreliable) way to indicate the end of the body is to close the connection after all body bytes have been sent.
The encoder tries to calculate the content length by buffering the body data up to the "pending" limit. If the body is smaller than the limit, the message is set with the calculated content length header, else the data is sent without such a header and the connection is closed.
If the response protocol is HTTP/1.1 and there is no "Content-Length" header, chunked transfer encoding is used.
- Returns:
- the limit
-
setPendingLimit
Sets the limit for the pending body bytes.- Parameters:
pendingLimit- the limit to set
-
isClosed
Returns true if the encoder does not accept further input because the processed data indicated that the connection has been or is to be closed.- Returns:
- the result
-
startMessage
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.
- Parameters:
messageHeader- the message header to encode (seeencode(HttpMessageHeader)writer- the Writer to use for writing- Throws:
IOException- if an I/O error occurs
-
forceCloseAfterBody
Force close after body.Used to override the header driven behavior for HTTP/1.0 responses.
- Returns:
- true, if forced
-
encode
Set a new HTTP message that is to be encoded.- Specified by:
encodein interfaceEncoder<T extends HttpMessageHeader,D extends HttpMessageHeader> - Parameters:
messageHeader- the response
-
encode
Encodes a HTTP message.- Specified by:
encodein interfaceEncoder<T extends HttpMessageHeader,D extends HttpMessageHeader> - 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
-
header
Description copied from interface:EncoderReturns the last message (header) encoded.- Specified by:
headerin interfaceEncoder<T extends HttpMessageHeader,D extends HttpMessageHeader> - Returns:
- the result
-