Class HttpObjectEncoder<H extends HttpMessage>

    • Field Detail

      • ZERO_CRLF_CRLF

        private static final byte[] ZERO_CRLF_CRLF
      • CRLF_BUF

        private static final ByteBuf CRLF_BUF
      • ZERO_CRLF_CRLF_BUF

        private static final ByteBuf ZERO_CRLF_CRLF_BUF
      • HEADERS_WEIGHT_HISTORICAL

        private static final float HEADERS_WEIGHT_HISTORICAL
        See Also:
        Constant Field Values
      • TRAILERS_WEIGHT_HISTORICAL

        private static final float TRAILERS_WEIGHT_HISTORICAL
        See Also:
        Constant Field Values
      • ST_CONTENT_ALWAYS_EMPTY

        private static final int ST_CONTENT_ALWAYS_EMPTY
        See Also:
        Constant Field Values
      • state

        private int state
      • headersEncodedSizeAccumulator

        private float headersEncodedSizeAccumulator
        Used to calculate an exponential moving average of the encoded size of the initial line and the headers for a guess for future buffer allocations.
      • trailersEncodedSizeAccumulator

        private float trailersEncodedSizeAccumulator
        Used to calculate an exponential moving average of the encoded size of the trailers for a guess for future buffer allocations.
      • out

        private final java.util.List<java.lang.Object> out
    • Constructor Detail

      • HttpObjectEncoder

        public HttpObjectEncoder()
    • Method Detail

      • checkContentState

        private static boolean checkContentState​(int state)
      • writeVoidPromise

        private static void writeVoidPromise​(ChannelHandlerContext ctx,
                                             java.util.List<java.lang.Object> out)
      • encode

        protected void encode​(ChannelHandlerContext ctx,
                              java.lang.Object msg,
                              java.util.List<java.lang.Object> out)
                       throws java.lang.Exception
        Description copied from class: MessageToMessageEncoder
        Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.
        Specified by:
        encode in class MessageToMessageEncoder<java.lang.Object>
        Parameters:
        ctx - the ChannelHandlerContext which this MessageToMessageEncoder belongs to
        msg - the message to encode to an other one
        out - the List into which the encoded msg should be added needs to do some kind of aggregation
        Throws:
        java.lang.Exception - is thrown if an error occurs
      • encodeJustHttpMessage

        private void encodeJustHttpMessage​(ChannelHandlerContext ctx,
                                           H m,
                                           java.util.List<java.lang.Object> out)
                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • encodeHttpMessageNotLastContent

        private void encodeHttpMessageNotLastContent​(ChannelHandlerContext ctx,
                                                     H m,
                                                     java.util.List<java.lang.Object> out)
                                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • encodeHttpMessageLastContent

        private void encodeHttpMessageLastContent​(ChannelHandlerContext ctx,
                                                  H m,
                                                  java.util.List<java.lang.Object> out)
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • encodeNotHttpMessageContentTypes

        private void encodeNotHttpMessageContentTypes​(ChannelHandlerContext ctx,
                                                      java.lang.Object msg,
                                                      java.util.List<java.lang.Object> out)
      • encodeFullHttpMessage

        private void encodeFullHttpMessage​(ChannelHandlerContext ctx,
                                           java.lang.Object o,
                                           java.util.List<java.lang.Object> out)
                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • encodeContentNonChunk

        private static boolean encodeContentNonChunk​(java.util.List<java.lang.Object> out,
                                                     ByteBuf buf,
                                                     ByteBuf content)
      • throwUnexpectedMessageTypeEx

        private static void throwUnexpectedMessageTypeEx​(java.lang.Object msg,
                                                         int state)
      • bypassEncoderIfEmpty

        private static boolean bypassEncoderIfEmpty​(ByteBuf msg,
                                                    java.util.List<java.lang.Object> out)
      • encodeByteBufContent

        private void encodeByteBufContent​(ChannelHandlerContext ctx,
                                          ByteBuf content,
                                          java.util.List<java.lang.Object> out)
      • encodeEmptyLastHttpContent

        private static int encodeEmptyLastHttpContent​(int state,
                                                      java.util.List<java.lang.Object> out)
      • encodeByteBufAndTrailers

        private void encodeByteBufAndTrailers​(int state,
                                              ChannelHandlerContext ctx,
                                              java.util.List<java.lang.Object> out,
                                              ByteBuf content,
                                              HttpHeaders trailingHeaders)
      • encodeTrailingHeaders

        private void encodeTrailingHeaders​(ChannelHandlerContext ctx,
                                           HttpHeaders trailingHeaders,
                                           java.util.List<java.lang.Object> out)
      • encodeInitHttpMessage

        private ByteBuf encodeInitHttpMessage​(ChannelHandlerContext ctx,
                                              H m)
                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • encodedChunkedFileRegionContent

        private static void encodedChunkedFileRegionContent​(ChannelHandlerContext ctx,
                                                            FileRegion msg,
                                                            java.util.List<java.lang.Object> out)
      • addEncodedLengthHex

        private static void addEncodedLengthHex​(ChannelHandlerContext ctx,
                                                long contentLength,
                                                java.util.List<java.lang.Object> out)
      • 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
      • padSizeForAccumulation

        private static int padSizeForAccumulation​(int readableBytes)
        Add some additional overhead to the buffer. The rational is that it is better to slightly over allocate and waste some memory, rather than under allocate and require a resize/copy.
        Parameters:
        readableBytes - The readable bytes in the buffer.
        Returns:
        The readableBytes with some additional padding.
      • encodeAscii

        @Deprecated
        protected static void encodeAscii​(java.lang.String s,
                                          ByteBuf buf)
        Deprecated.
      • encodeInitialLine

        protected abstract void encodeInitialLine​(ByteBuf buf,
                                                  H message)
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception