Class HTTPHelper


  • @ThreadSafe
    public final class HTTPHelper
    extends Object
    HTTP utility methods.
    Author:
    Philip Helger
    • Field Detail

      • MA_HTTP_REQ_VERSION

        public static final String MA_HTTP_REQ_VERSION
        The HTTP version used. E.g. "HTTP/1.1"
        See Also:
        Constant Field Values
      • MA_HTTP_ORIGINAL_CONTENT_TRANSFER_ENCODING

        public static final String MA_HTTP_ORIGINAL_CONTENT_TRANSFER_ENCODING
        The value of the Content-Transfer-Encoding header (if provided)
        See Also:
        Constant Field Values
      • MA_HTTP_ORIGINAL_CONTENT_LENGTH

        public static final String MA_HTTP_ORIGINAL_CONTENT_LENGTH
        The original content length before any eventual decoding (only if Content-Transfer-Encoding is provided)
        See Also:
        Constant Field Values
    • Method Detail

      • getAllHTTPHeaderLines

        @Nonnull
        @ReturnsMutableCopy
        public static com.helger.commons.collection.impl.ICommonsList<String> getAllHTTPHeaderLines​(@Nonnull
                                                                                                    com.helger.commons.http.HttpHeaderMap aHeaders)
      • getHTTPIncomingDumper

        @Nullable
        public static IHTTPIncomingDumper getHTTPIncomingDumper()
        Returns:
        the global dumper for incoming HTTP requests or null if none is present
        Since:
        3.0.1
      • getHTTPIncomingDumperFactory

        @Nonnull
        public static Supplier<? extends IHTTPIncomingDumper> getHTTPIncomingDumperFactory()
        Returns:
        the global dumper factory for incoming HTTP requests. Never null.
        Since:
        4.4.0
      • setHTTPIncomingDumperFactory

        public static void setHTTPIncomingDumperFactory​(@Nonnull
                                                        Supplier<? extends IHTTPIncomingDumper> aHttpDumperFactory)
        Set the global factory for creating dumper for incoming HTTP requests.
        Parameters:
        aHttpDumperFactory - The dumper factory to be used. May not be null.
        Since:
        3.1.0
      • readHttpRequest

        @Nonnull
        public static com.helger.mail.datasource.IExtendedDataSource readHttpRequest​(@Nonnull
                                                                                     IAS2HttpRequestDataProvider aRDP,
                                                                                     @Nonnull
                                                                                     IAS2HttpResponseHandler aResponseHandler,
                                                                                     @Nonnull
                                                                                     IMessage aMsg,
                                                                                     @Nullable
                                                                                     IHTTPIncomingDumper aIncomingDumper)
                                                                              throws IOException,
                                                                                     jakarta.mail.MessagingException
        Read headers and payload from the passed input stream provider. For large file support, return DataSource. If is on, data is not read.
        Parameters:
        aRDP - The abstract input stream provider to use. May not be null.
        aResponseHandler - The HTTP response handler to be used. May not be null.
        aMsg - The Message to be filled. May not be null.
        aIncomingDumper - Optional incoming HTTP dumper. May be null.
        Returns:
        A IExtendedDataSource that holds/refers to the body.
        Throws:
        IOException - In case of error reading from the InputStream
        jakarta.mail.MessagingException - In case header line parsing fails
      • sendSimpleHTTPResponse

        public static void sendSimpleHTTPResponse​(@Nonnull
                                                  IAS2HttpResponseHandler aResponseHandler,
                                                  @Nonnegative
                                                  int nResponseCode)
                                           throws IOException
        Send a simple HTTP response that only contains the HTTP status code and the respective descriptive text. An empty header map us used.
        Parameters:
        aResponseHandler - The response handler to be used.
        nResponseCode - The HTTP response code to use.
        Throws:
        IOException - In case sending fails for whatever reason
      • readChunkLen

        public static int readChunkLen​(@Nonnull @WillNotClose
                                       InputStream aIS)
                                throws IOException
        Read chunk size (including the newline ending it). Discard any other data, e.g. headers that my be there.
        Parameters:
        aIS - - input stream to read from
        Returns:
        Chunk length
        Throws:
        IOException - if stream ends during chunk length read