Module io.netty5.codec.http
Package io.netty5.handler.codec.http
Class HttpObjectEncoder<H extends HttpMessage>
- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageEncoder<Object>
-
- io.netty5.handler.codec.http.HttpObjectEncoder<H>
-
- All Implemented Interfaces:
ChannelHandler
- Direct Known Subclasses:
HttpRequestEncoder
,HttpResponseEncoder
,RtspEncoder
public abstract class HttpObjectEncoder<H extends HttpMessage> extends MessageToMessageEncoder<Object>
Encodes anHttpMessage
or anHttpContent
into aBuffer
.Extensibility
Please note that this encoder is designed to be extended to implement a protocol derived from HTTP, such as RTSP and ICAP. To implement the encoder of such a derived protocol, extend this class and implement all abstract methods properly.
-
-
Constructor Summary
Constructors Constructor Description HttpObjectEncoder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
acceptOutboundMessage(Object msg)
Returnstrue
if the given message should be handled.protected Buffer
crlfBuffer(BufferAllocator allocator)
protected void
encodeAndClose(ChannelHandlerContext ctx, Object msg, List<Object> out)
Encode from one message to another.protected void
encodeHeaders(HttpHeaders headers, Buffer buf)
Encode theHttpHeaders
into aBuffer
.protected abstract void
encodeInitialLine(Buffer buf, H message)
protected boolean
isContentAlwaysEmpty(H msg)
Determine whether a message has a content or not.protected void
sanitizeHeadersBeforeEncode(H msg, boolean isAlwaysEmpty)
Allows to sanitize headers of the message before encoding these.protected Buffer
zeroCrlfCrlfBuffer(BufferAllocator allocator)
-
Methods inherited from class io.netty5.handler.codec.MessageToMessageEncoder
encode, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
-
-
-
-
Method Detail
-
encodeAndClose
protected void encodeAndClose(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception
Description copied from class:MessageToMessageEncoder
Encode from one message to another. This method will be called for each written message that can be handled by this encoder.The message will not be automatically disposed of after this call. Instead, the responsibility of ensuring that messages are disposed of falls upon the implementor of this method.
Subclasses that wish to have incoming messages automatically disposed of should instead override the
MessageToMessageEncoder.encode(ChannelHandlerContext, Object, List)
method.- Overrides:
encodeAndClose
in classMessageToMessageEncoder<Object>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToMessageEncoder
belongs to.msg
- the message to encode to another one.out
- theList
into which produced output messages should be added.- Throws:
Exception
- is thrown if an error occurs.
-
encodeHeaders
protected void encodeHeaders(HttpHeaders headers, Buffer buf)
Encode theHttpHeaders
into aBuffer
.
-
sanitizeHeadersBeforeEncode
protected void sanitizeHeadersBeforeEncode(H msg, boolean isAlwaysEmpty)
Allows to sanitize headers of the message before encoding these.
-
isContentAlwaysEmpty
protected boolean isContentAlwaysEmpty(H msg)
Determine whether a message has a content or not. Some message may have headers indicating a content without having an actual content, e.g the response to an HEAD or CONNECT request.- Parameters:
msg
- the message to test- Returns:
true
to signal the message has no content
-
acceptOutboundMessage
public boolean acceptOutboundMessage(Object msg) throws Exception
Description copied from class:MessageToMessageEncoder
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelHandler
in theChannelPipeline
.- Overrides:
acceptOutboundMessage
in classMessageToMessageEncoder<Object>
- Throws:
Exception
-
encodeInitialLine
protected abstract void encodeInitialLine(Buffer buf, H message) throws Exception
- Throws:
Exception
-
crlfBuffer
protected Buffer crlfBuffer(BufferAllocator allocator)
-
zeroCrlfCrlfBuffer
protected Buffer zeroCrlfCrlfBuffer(BufferAllocator allocator)
-
-