Class HttpPostMultipartRequestDecoder

    • Field Detail

      • factory

        private final HttpDataFactory factory
        Factory used to create InterfaceHttpData
      • request

        private final HttpRequest request
        Request to decode
      • maxFields

        private final int maxFields
        The maximum number of fields allows by the form
      • maxBufferedBytes

        private final int maxBufferedBytes
        The maximum number of accumulated bytes when decoding a field
      • charset

        private java.nio.charset.Charset charset
        Default charset to use
      • isLastChunk

        private boolean isLastChunk
        Does the last chunk already received
      • bodyListHttpData

        private final java.util.List<InterfaceHttpData> bodyListHttpData
        HttpDatas from Body
      • bodyMapHttpData

        private final java.util.Map<java.lang.String,​java.util.List<InterfaceHttpData>> bodyMapHttpData
        HttpDatas as Map from Body
      • undecodedChunk

        private ByteBuf undecodedChunk
        The current channelBuffer
      • bodyListHttpDataRank

        private int bodyListHttpDataRank
        Body HttpDatas current position
      • multipartDataBoundary

        private final java.lang.String multipartDataBoundary
        If multipart, this is the boundary for the global multipart
      • multipartMixedBoundary

        private java.lang.String multipartMixedBoundary
        If multipart, there could be internal multiparts (mixed) to the global multipart. Only one level is allowed.
      • currentFieldAttributes

        private java.util.Map<java.lang.CharSequence,​Attribute> currentFieldAttributes
        Used in Multipart
      • currentFileUpload

        private FileUpload currentFileUpload
        The current FileUpload that is currently in decode process
      • currentAttribute

        private Attribute currentAttribute
        The current Attribute that is currently in decode process
      • destroyed

        private boolean destroyed
      • discardThreshold

        private int discardThreshold
      • FILENAME_ENCODED

        private static final java.lang.String FILENAME_ENCODED
    • Constructor Detail

      • HttpPostMultipartRequestDecoder

        public HttpPostMultipartRequestDecoder​(HttpRequest request)
        Parameters:
        request - the request to decode
        Throws:
        java.lang.NullPointerException - for request
        HttpPostRequestDecoder.ErrorDataDecoderException - if the default charset was wrong when decoding or other errors
      • HttpPostMultipartRequestDecoder

        public HttpPostMultipartRequestDecoder​(HttpDataFactory factory,
                                               HttpRequest request)
        Parameters:
        factory - the factory used to create InterfaceHttpData
        request - the request to decode
        Throws:
        java.lang.NullPointerException - for request or factory
        HttpPostRequestDecoder.ErrorDataDecoderException - if the default charset was wrong when decoding or other errors
      • HttpPostMultipartRequestDecoder

        public HttpPostMultipartRequestDecoder​(HttpDataFactory factory,
                                               HttpRequest request,
                                               java.nio.charset.Charset charset)
        Parameters:
        factory - the factory used to create InterfaceHttpData
        request - the request to decode
        charset - the charset to use as default
        Throws:
        java.lang.NullPointerException - for request or charset or factory
        HttpPostRequestDecoder.ErrorDataDecoderException - if the default charset was wrong when decoding or other errors
      • HttpPostMultipartRequestDecoder

        public HttpPostMultipartRequestDecoder​(HttpDataFactory factory,
                                               HttpRequest request,
                                               java.nio.charset.Charset charset,
                                               int maxFields,
                                               int maxBufferedBytes)
        Parameters:
        factory - the factory used to create InterfaceHttpData
        request - the request to decode
        charset - the charset to use as default
        maxFields - the maximum number of fields the form can have, -1 to disable
        maxBufferedBytes - the maximum number of bytes the decoder can buffer when decoding a field, -1 to disable
        Throws:
        java.lang.NullPointerException - for request or charset or factory
        HttpPostRequestDecoder.ErrorDataDecoderException - if the default charset was wrong when decoding or other errors
    • Method Detail

      • checkDestroyed

        private void checkDestroyed()
      • isMultipart

        public boolean isMultipart()
        True if this request is a Multipart request
        Specified by:
        isMultipart in interface InterfaceHttpPostRequestDecoder
        Returns:
        True if this request is a Multipart request
      • setDiscardThreshold

        public void setDiscardThreshold​(int discardThreshold)
        Set the amount of bytes after which read bytes in the buffer should be discarded. Setting this lower gives lower memory usage but with the overhead of more memory copies. Use 0 to disable it.
        Specified by:
        setDiscardThreshold in interface InterfaceHttpPostRequestDecoder
      • currentPartialHttpData

        public InterfaceHttpData currentPartialHttpData()
        Description copied from interface: InterfaceHttpPostRequestDecoder
        Returns the current InterfaceHttpData if currently in decoding status, meaning all data are not yet within, or null if there is no InterfaceHttpData currently in decoding status (either because none yet decoded or none currently partially decoded). Full decoded ones are accessible through hasNext() and next() methods.
        Specified by:
        currentPartialHttpData in interface InterfaceHttpPostRequestDecoder
        Returns:
        the current InterfaceHttpData if currently in decoding status or null if none.
      • addHttpData

        protected void addHttpData​(InterfaceHttpData data)
        Utility function to add a new decoded data
      • decodeMultipart

        private InterfaceHttpData decodeMultipart​(HttpPostRequestDecoder.MultiPartStatus state)
        Decode a multipart request by pieces

        NOTSTARTED PREAMBLE (
        (HEADERDELIMITER DISPOSITION (FIELD | FILEUPLOAD))*
        (HEADERDELIMITER DISPOSITION MIXEDPREAMBLE
        (MIXEDDELIMITER MIXEDDISPOSITION MIXEDFILEUPLOAD)+
        MIXEDCLOSEDELIMITER)*
        CLOSEDELIMITER)+ EPILOGUE
        Inspired from HttpMessageDecoder
        Returns:
        the next decoded InterfaceHttpData or null if none until now.
        Throws:
        HttpPostRequestDecoder.ErrorDataDecoderException - if an error occurs
      • skipControlCharactersStandard

        private static void skipControlCharactersStandard​(ByteBuf undecodedChunk)
      • getContentDispositionAttribute

        private Attribute getContentDispositionAttribute​(java.lang.String... values)
      • cleanMixedAttributes

        private void cleanMixedAttributes()
        Remove all Attributes that should be cleaned between two FileUpload in Mixed mode
      • readLineOptimized

        private static java.lang.String readLineOptimized​(ByteBuf undecodedChunk,
                                                          java.nio.charset.Charset charset)
        Read one line up to the CRLF or LF
        Returns:
        the String from one line
        Throws:
        HttpPostRequestDecoder.NotEnoughDataDecoderException - Need more chunks and reset the readerIndex to the previous value
      • readDelimiterOptimized

        private static java.lang.String readDelimiterOptimized​(ByteBuf undecodedChunk,
                                                               java.lang.String delimiter,
                                                               java.nio.charset.Charset charset)
        Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF. Note that CRLF or LF are mandatory for opening delimiter (--delimiter) but not for closing delimiter (--delimiter--) since some clients does not include CRLF in this case.
        Parameters:
        delimiter - of the form --string, such that '--' is already included
        Returns:
        the String from one line as the delimiter searched (opening or closing)
        Throws:
        HttpPostRequestDecoder.NotEnoughDataDecoderException - Need more chunks and reset the readerIndex to the previous value
      • rewriteCurrentBuffer

        private static void rewriteCurrentBuffer​(ByteBuf buffer,
                                                 int lengthToSkip)
        Rewrite buffer in order to skip lengthToSkip bytes from current readerIndex, such that any readable bytes available after readerIndex + lengthToSkip (so before writerIndex) are moved at readerIndex position, therefore decreasing writerIndex of lengthToSkip at the end of the process.
        Parameters:
        buffer - the buffer to rewrite from current readerIndex
        lengthToSkip - the size to skip from readerIndex
      • loadDataMultipartOptimized

        private static boolean loadDataMultipartOptimized​(ByteBuf undecodedChunk,
                                                          java.lang.String delimiter,
                                                          HttpData httpData)
        Load the field value or file data from a Multipart request
        Returns:
        true if the last chunk is loaded (boundary delimiter found), false if need more chunks
        Throws:
        HttpPostRequestDecoder.ErrorDataDecoderException
      • cleanString

        private static java.lang.String cleanString​(java.lang.String field)
        Clean the String from any unallowed character
        Returns:
        the cleaned String
      • skipOneLine

        private boolean skipOneLine()
        Skip one empty line
        Returns:
        True if one empty line was skipped
      • splitMultipartHeader

        private static java.lang.String[] splitMultipartHeader​(java.lang.String sb)
        Split one header in Multipart
        Returns:
        an array of String where rank 0 is the name of the header, follows by several values that were separated by ';' or ','
      • splitMultipartHeaderValues

        private static java.lang.String[] splitMultipartHeaderValues​(java.lang.String svalue)
        Split one header value in Multipart
        Returns:
        an array of String where values that were separated by ';' or ','
      • getCurrentAllocatedCapacity

        int getCurrentAllocatedCapacity()
        This method is package private intentionally in order to allow during tests to access to the amount of memory allocated (capacity) within the private ByteBuf undecodedChunk
        Returns:
        the number of bytes the internal buffer can contain