Class HttpCodecFilter

    • Field Detail

      • DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE

        public static final int DEFAULT_MAX_HTTP_PACKET_HEADER_SIZE
        See Also:
        Constant Field Values
      • CLOSE_BYTES

        protected static final byte[] CLOSE_BYTES
        Close bytes.
      • KEEPALIVE_BYTES

        protected static final byte[] KEEPALIVE_BYTES
        Keep-alive bytes.
      • chunkingEnabled

        protected final boolean chunkingEnabled
      • maxPayloadRemainderToSkip

        protected long maxPayloadRemainderToSkip
        The maximum request payload remainder (in bytes) HttpServerFilter will try to swallow after HTTP request processing is over in order to keep the connection alive. If the remainder is too large - HttpServerFilter will close the connection.
      • maxHeadersSize

        protected final int maxHeadersSize
      • preserveHeaderCase

        protected boolean preserveHeaderCase
    • Constructor Detail

      • HttpCodecFilter

        public HttpCodecFilter​(boolean chunkingEnabled,
                               int maxHeadersSize)
        Constructor, which creates HttpCodecFilter instance, with the specific max header size parameter.
        Parameters:
        chunkingEnabled - true if the chunked transfer encoding should be used when no explicit content length has been set.
        maxHeadersSize - the maximum size of the HTTP message header.
    • Method Detail

      • onHttpPacketParsed

        protected abstract boolean onHttpPacketParsed​(HttpHeader httpHeader,
                                                      FilterChainContext ctx)
        Callback method, called when HttpPacket parsing has been completed.
        Parameters:
        httpHeader - HttpHeader, which represents parsed HTTP packet header
        ctx - processing context.
        Returns:
        true if an error has occurred while processing the header portion of the HTTP request, otherwise returns false.s
      • onHttpHeaderParsed

        protected abstract boolean onHttpHeaderParsed​(HttpHeader httpHeader,
                                                      Buffer buffer,
                                                      FilterChainContext ctx)
        Callback invoked when the HTTP message header parsing is complete.
        Parameters:
        httpHeader - HttpHeader, which represents parsed HTTP packet header
        buffer - Buffer the header was parsed from
        ctx - processing context.
        Returns:
        true if an error has occurred while processing the header portion of the HTTP request, otherwise returns false.
      • onInitialLineParsed

        protected abstract void onInitialLineParsed​(HttpHeader httpHeader,
                                                    FilterChainContext ctx)

        Invoked when either the request line or status line has been parsed.

        Parameters:
        httpHeader - HttpHeader, which represents HTTP packet header
        ctx - processing context.
      • onInitialLineEncoded

        protected abstract void onInitialLineEncoded​(HttpHeader httpHeader,
                                                     FilterChainContext ctx)

        Invoked when the initial response line has been encoded in preparation to being transmitted to the user-agent.

        Parameters:
        httpHeader - HttpHeader, which represents HTTP packet header
        ctx - processing context.
        Since:
        2.1.2
      • onHttpHeadersParsed

        protected abstract void onHttpHeadersParsed​(HttpHeader httpHeader,
                                                    MimeHeaders headers,
                                                    FilterChainContext ctx)

        Invoked when HTTP headers portion comes for HttpHeader message. Depending on the transfer encoding being used by the current request, this method may be invoked multiple times.

        Parameters:
        httpHeader - HttpHeader, which represents HTTP packet header
        headers - the headers portion, that has been parsed
        ctx - processing context.
      • onHttpHeadersEncoded

        protected abstract void onHttpHeadersEncoded​(HttpHeader httpHeader,
                                                     FilterChainContext ctx)

        Invoked when HTTP headers have been encoded in preparation to being transmitted to the user-agent.

        Parameters:
        httpHeader - HttpHeader, which represents HTTP packet header
        ctx - processing context.
        Since:
        2.1.2
      • onHttpContentParsed

        protected abstract void onHttpContentParsed​(HttpContent content,
                                                    FilterChainContext ctx)

        Invoked as request/response body content has been processed by this Filter.

        Parameters:
        content - request/response body content
        ctx - processing context.
      • onHttpContentEncoded

        protected abstract void onHttpContentEncoded​(HttpContent content,
                                                     FilterChainContext ctx)

        Invoked when a HTTP body chunk has been encoded in preparation to being transmitted to the user-agent.

        Parameters:
        content - HttpContent, which represents HTTP packet header
        ctx - processing context.
        Since:
        2.1.2
      • onHttpHeaderError

        protected abstract void onHttpHeaderError​(HttpHeader httpHeader,
                                                  FilterChainContext ctx,
                                                  java.lang.Throwable t)
                                           throws java.io.IOException

        Callback which is invoked when parsing an HTTP message header fails. The processing logic has to take care about error handling and following connection closing.

        Parameters:
        httpHeader - HttpHeader, which represents HTTP packet header
        ctx - the FilterChainContext processing this request
        t - the cause of the error
        Throws:
        java.io.IOException
      • onHttpContentError

        protected abstract void onHttpContentError​(HttpHeader httpHeader,
                                                   FilterChainContext ctx,
                                                   java.lang.Throwable t)
                                            throws java.io.IOException

        Callback which is invoked when parsing an HTTP message payload fails. The processing logic has to take care about error handling and following connection closing.

        Parameters:
        httpHeader - HttpHeader, which represents HTTP packet header
        ctx - the FilterChainContext processing this request
        t - the cause of the error
        Throws:
        java.io.IOException
      • getMaxPayloadRemainderToSkip

        public long getMaxPayloadRemainderToSkip()
        Returns:
        the maximum request payload remainder (in bytes) HttpServerFilter will try to swallow after HTTP request processing is over in order to keep the connection alive. If the remainder is too large - the connection will be closed. -1 means no limits will be applied.
        Since:
        2.3.13
      • setMaxPayloadRemainderToSkip

        public void setMaxPayloadRemainderToSkip​(long maxPayloadRemainderToSkip)
        Set the maximum request payload remainder (in bytes) HttpServerFilter will try to swallow after HTTP request processing is over in order to keep the connection alive. If the remainder is too large - the connection will be closed. -1 means no limits will be applied.
        Parameters:
        maxPayloadRemainderToSkip -
        Since:
        2.3.13
      • isPreserveHeaderCase

        public boolean isPreserveHeaderCase()
        Returns:
        true if header case will be preserved, otherwise false. Default is false.
      • setPreserveHeaderCase

        public void setPreserveHeaderCase​(boolean preserveHeaderCase)
        Set to true to preserve header case. Default is false.
        Parameters:
        preserveHeaderCase - true to preserve header case.
      • isChunkingEnabled

        protected boolean isChunkingEnabled()
        Return true if chunked transfer-encoding may be used.
        Returns:
        true if chunked transfer-encoding may be used.
        Since:
        2.1.2
      • isRemoveHandledContentEncodingHeaders

        public boolean isRemoveHandledContentEncodingHeaders()
        Returns:
        true if content-encoding headers that are handled by this module should be removed from the header
        Since:
        2.3.39
        See Also:
        setRemoveHandledContentEncodingHeaders(boolean)
      • setRemoveHandledContentEncodingHeaders

        public void setRemoveHandledContentEncodingHeaders​(boolean removeHandledContentEncodingHeaders)

        If enabled the content-encoding header for handled content-encodings is removed.

        The primary usecase for this option is the use in a servlet container that enables compression handling on the server level. In this case the next level (the webapplication) has to be notified, that compression of the stream has been dealt with.
        For this usecase it is assumed, that a servlet filter might be present that also does compression/decompression. To prevent double decompression the content-encoding header is removed, so the servlet filter can't assume it needs to decode.

        Parameters:
        removeHandledContentEncodingHeaders - true if content-encoding headers that are handled by this module should be removed from the header
        Since:
        2.3.39
      • handleRead

        public final NextAction handleRead​(FilterChainContext ctx,
                                           HttpHeader httpHeader)
                                    throws java.io.IOException
        The method is called by the specific HttpCodecFilter implementation, once we have received a Buffer, which has to be transformed into HTTP packet part. Filter gets Buffer, which represents a part or complete HTTP message. As the result of "read" transformation - we will get HttpContent message, which will represent HTTP packet content (might be zero length content) and reference to a HttpHeader, which contains HTTP message header.
        Parameters:
        ctx - Request processing context
        httpHeader - the current HttpHeader, which is being processed.
        Returns:
        NextAction
        Throws:
        java.io.IOException
      • handleWrite

        public NextAction handleWrite​(FilterChainContext ctx)
                               throws java.io.IOException
        The method is called, once we need to serialize a HttpPacket, which may represent HTTP packet header, content or content chunk. Filter gets HttpPacket, which represents a HTTP header, content, or content part. As the result of "write" transformation - we will get Buffer, which will represent serialized HTTP packet.
        Specified by:
        handleWrite in interface Filter
        Overrides:
        handleWrite in class BaseFilter
        Parameters:
        ctx - Request processing context
        Returns:
        NextAction
        Throws:
        java.io.IOException
      • onIncomingUpgrade

        protected void onIncomingUpgrade​(FilterChainContext ctx,
                                         HttpHeader httpHeader)
        The method is called, when a peer sends an upgrade HTTP packet (either request or response).
        Parameters:
        ctx -
        httpHeader -
      • isSecure

        protected static boolean isSecure​(Connection connection)
        flag, which indicates whether this HttpCodecFilter is dealing with the secured HTTP packets. For this filter flag means nothing, it's just a value, which is getting set to a HttpRequestPacket or HttpResponsePacket.
        Parameters:
        connection - Connection
        Returns:
        true, if the Connection is secured, or false otherwise
      • statusDropsConnection

        protected static boolean statusDropsConnection​(int status)
        Determine if we must drop the connection because of the HTTP status code. Use the same list of codes as Apache/httpd.
      • createJmxManagementObject

        protected java.lang.Object createJmxManagementObject()