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

public abstract Class HttpContentEncoder

extends MessageToMessageCodec<HttpRequest, HttpObject>
Class Inheritance
Known Direct Subclasses
io.netty.handler.codec.http.HttpContentCompressor
Imports
io.netty.buffer.ByteBuf, .ByteBufHolder, .Unpooled, io.netty.channel.ChannelHandlerContext, io.netty.channel.embedded.EmbeddedChannel, io.netty.handler.codec.DecoderResult, .MessageToMessageCodec, io.netty.util.ReferenceCountUtil, io.netty.util.internal.ObjectUtil, .StringUtil, java.util.ArrayDeque, .List, .Queue

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 ByteBufs.

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 EmbeddedChannel
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.netty.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
private void
private void
protected void
protected void
private void
private boolean
private void
private static void
private static void
private void
private void
public void
handlerRemoved(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.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.netty.handler.codec.MessageToMessageCodec:
acceptInboundMessagechannelReadwrite

Field Detail

acceptEncodingQueueback to summary
private final Queue<CharSequence> acceptEncodingQueue
encoderback to summary
private EmbeddedChannel encoder

Hides io.netty.handler.codec.MessageToMessageCodec.encoder.

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.netty.handler.codec.MessageToMessageCodec.acceptOutboundMessage.

Doc from io.netty.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 io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Implements io.netty.channel.ChannelInboundHandler.channelInactive.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelInactive.

Calls ChannelHandlerContext#fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

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, List<Object> out) throws Exception

Implements abstract io.netty.handler.codec.MessageToMessageCodec.decode.

Annotations
@Override
encodeback to summary
protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception

Implements abstract io.netty.handler.codec.MessageToMessageCodec.encode.

Annotations
@Override
encodeback to summary
private void encode(ByteBuf in, List<Object> out)
encodeContentback to summary
private boolean encodeContent(HttpContent c, List<Object> out)
encodeFullResponseback to summary
private void encodeFullResponse(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)
fetchEncoderOutputback to summary
private void fetchEncoderOutput(List<Object> out)
finishEncodeback to summary
private void finishEncode(List<Object> out)
handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Doc from io.netty.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.netty.handler.codec.http back to summary

public final Class HttpContentEncoder.Result

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final EmbeddedChannel
private final String

Constructor Summary

AccessConstructor and Description
public
Result(String targetContentEncoding, EmbeddedChannel contentEncoder)

Method Summary

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

Field Detail

contentEncoderback to summary
private final EmbeddedChannel contentEncoder
targetContentEncodingback to summary
private final String targetContentEncoding

Constructor Detail

Resultback to summary
public Result(String targetContentEncoding, EmbeddedChannel contentEncoder)

Method Detail

contentEncoderback to summary
public EmbeddedChannel contentEncoder()
targetContentEncodingback to summary
public String targetContentEncoding()
io.netty.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()