Top Description Inners Fields Constructors Methods
io.netty5.handler.codec.http

public abstract Class HttpContentEncoder

extends MessageToMessageCodec<HttpRequest, HttpObject>
Class Inheritance
Known Direct Subclasses
io.netty5.handler.codec.http.HttpContentCompressor
Imports
io.netty5.buffer.Buffer, .BufferAllocator, io.netty5.channel.ChannelHandlerContext, io.netty5.channel.embedded.EmbeddedChannel, io.netty5.handler.codec.MessageToMessageCodec, io.netty5.handler.codec.compression.Compressor, io.netty5.handler.codec.http.headers.HttpHeaders, io.netty5.util.Resource, java.util.ArrayDeque, .Iterator, .List, .Queue, .StringJoiner

Encodes the content of the outbound HttpResponse and HttpContent. The original content is replaced with the new content encoded by the EmbeddedChannel, which is created by beginEncode(HttpResponse, String). Once encoding is finished, the value of the 'Content-Encoding' header is set to the target content encoding, as returned by beginEncode(HttpResponse, String). Also, the 'Content-Length' header is updated to the length of the encoded content. If there is no supported or allowed encoding in the corresponding HttpRequest's "Accept-Encoding" header, beginEncode(HttpResponse, String) should return null so that no encoding occurs (i.e. pass-through).

Please note that this is an abstract class. You have to extend this class and implement beginEncode(HttpResponse, String) properly to make this class functional. For example, refer to the source code of HttpContentCompressor.

This handler must be placed after HttpObjectEncoder in the pipeline so that this handler can intercept HTTP responses before HttpObjectEncoder converts them into Buffers.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
private static enum

Field Summary

Modifier and TypeField and Description
private final Queue<CharSequence>
private Compressor
private static final int
private HttpContentEncoder.State
private static final CharSequence
private static final CharSequence

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
acceptOutboundMessage(Object
the message
msg
)

Overrides io.netty5.handler.codec.MessageToMessageCodec.acceptOutboundMessage.

Returns true if and only if the specified message can be encoded by this codec.
protected abstract HttpContentEncoder.Result

Returns:

the result of preparation, which is composed of the determined target content encoding and a new EmbeddedChannel that encodes the content into the target content encoding. null if acceptEncoding is unsupported or rejected and thus the content should be handled as-is (i.e. no encoding).
beginEncode
(HttpResponse
the http response
httpResponse
,
String
the value of the "Accept-Encoding" header
acceptEncoding
)

Prepare to encode the HTTP message content.

public void
channelInactive(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.
private void
private void
protected void
protected void
private void
encode(Buffer in, BufferAllocator allocator, List<Object> out)

protected void
private boolean
private void
private static void
private static void
private void
public void
handlerRemoved(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.
private static boolean
isPassthru(HttpVersion version, int code, CharSequence httpMethod)

Inherited from io.netty5.handler.codec.MessageToMessageCodec:
acceptInboundMessagechannelReadencodewrite

Field Detail

acceptEncodingQueueback to summary
private final Queue<CharSequence> acceptEncodingQueue
compressorback to summary
private Compressor compressor
CONTINUE_CODEback to summary
private static final int CONTINUE_CODE
stateback to summary
private HttpContentEncoder.State state
ZERO_LENGTH_CONNECTback to summary
private static final CharSequence ZERO_LENGTH_CONNECT
ZERO_LENGTH_HEADback to summary
private static final CharSequence ZERO_LENGTH_HEAD

Constructor Detail

HttpContentEncoderback to summary
public HttpContentEncoder()

Method Detail

acceptOutboundMessageback to summary
public boolean acceptOutboundMessage(Object msg) throws Exception

Overrides io.netty5.handler.codec.MessageToMessageCodec.acceptOutboundMessage.

Doc from io.netty5.handler.codec.MessageToMessageCodec.acceptOutboundMessage.

Returns true if and only if the specified message can be encoded by this codec.

Parameters
msg:Object

the message

Annotations
@Override
beginEncodeback to summary
protected abstract HttpContentEncoder.Result beginEncode(HttpResponse httpResponse, String acceptEncoding) throws Exception

Prepare to encode the HTTP message content.

Parameters
httpResponse:HttpResponse

the http response

acceptEncoding:String

the value of the "Accept-Encoding" header

Returns:HttpContentEncoder.Result

the result of preparation, which is composed of the determined target content encoding and a new EmbeddedChannel that encodes the content into the target content encoding. null if acceptEncoding is unsupported or rejected and thus the content should be handled as-is (i.e. no encoding).

channelInactiveback to summary
public void channelInactive(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

Doc from io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

Annotations
@Override
cleanupback to summary
private void cleanup()
cleanupSafelyback to summary
private void cleanupSafely(ChannelHandlerContext ctx)
decodeback to summary
protected void decode(ChannelHandlerContext ctx, HttpRequest msg) throws Exception

Overrides io.netty5.handler.codec.MessageToMessageCodec.decode.

Annotations
@Override
decodeAndCloseback to summary
protected void decodeAndClose(ChannelHandlerContext ctx, HttpRequest msg) throws Exception

Overrides io.netty5.handler.codec.MessageToMessageCodec.decodeAndClose.

Annotations
@Override
encodeback to summary
private void encode(Buffer in, BufferAllocator allocator, List<Object> out)
encodeAndCloseback to summary
protected void encodeAndClose(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception

Overrides io.netty5.handler.codec.MessageToMessageCodec.encodeAndClose.

Annotations
@Override
encodeContentback to summary
private boolean encodeContent(ChannelHandlerContext ctx, HttpContent<?> c, List<Object> out)
encodeFullResponseback to summary
private void encodeFullResponse(ChannelHandlerContext ctx, HttpResponse newRes, HttpContent<?> content, List<Object> out)
ensureContentback to summary
private static void ensureContent(HttpObject msg)
ensureHeadersback to summary
private static void ensureHeaders(HttpObject msg)
finishEncodeback to summary
private void finishEncode(BufferAllocator allocator, List<Object> out)
handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.handlerRemoved.

Doc from io.netty5.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.

Annotations
@Override
isPassthruback to summary
private static boolean isPassthru(HttpVersion version, int code, CharSequence httpMethod)
io.netty5.handler.codec.http back to summary

public final Class HttpContentEncoder.Result

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Compressor
private final String

Constructor Summary

AccessConstructor and Description
public
Result(String targetContentEncoding, Compressor contentCompressor)

Method Summary

Modifier and TypeMethod and Description
public Compressor
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentCompressorback to summary
private final Compressor contentCompressor
targetContentEncodingback to summary
private final String targetContentEncoding

Constructor Detail

Resultback to summary
public Result(String targetContentEncoding, Compressor contentCompressor)

Method Detail

contentCompressorback to summary
public Compressor contentCompressor()
targetContentEncodingback to summary
public String targetContentEncoding()
io.netty5.handler.codec.http back to summary

private final Enum HttpContentEncoder.State

extends Enum<HttpContentEncoder.State>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final HttpContentEncoder.State
public static final HttpContentEncoder.State
public static final HttpContentEncoder.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static HttpContentEncoder.State
public static HttpContentEncoder.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AWAIT_CONTENTback to summary
public static final HttpContentEncoder.State AWAIT_CONTENT
AWAIT_HEADERSback to summary
public static final HttpContentEncoder.State AWAIT_HEADERS
PASS_THROUGHback to summary
public static final HttpContentEncoder.State PASS_THROUGH

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static HttpContentEncoder.State valueOf(String name)
valuesback to summary
public static HttpContentEncoder.State[] values()