Class ResponseHelper


  • @Immutable
    public final class ResponseHelper
    extends Object
    Misc. helper methods on HttpServletResponse objects.
    Consider using the UnifiedResponse for easy and consistent HTTP response handling.
    Author:
    Philip Helger
    • Method Detail

      • getBestSuitableOutputStreamType

        @Nonnull
        public static EResponseStreamType getBestSuitableOutputStreamType​(@Nonnull
                                                                          jakarta.servlet.http.HttpServletRequest aHttpRequest)
        Determine the best suitable output stream type for the given request without actually modifying response data. If the request supports gzip, the result is a EResponseStreamType.GZIP, if the request supports deflate or compress, the result will be a EResponseStreamType.DEFLATE. If none of that matches, the regular value EResponseStreamType.PLAIN will be returned.
        Parameters:
        aHttpRequest - request
        Returns:
        The best matching output stream type. Never null.
        See Also:
        ResponseHelperSettings
      • getBestSuitableOutputStream

        @Nonnull
        public static OutputStream getBestSuitableOutputStream​(@Nonnull
                                                               jakarta.servlet.http.HttpServletRequest aHttpRequest,
                                                               @Nonnull
                                                               jakarta.servlet.http.HttpServletResponse aHttpResponse)
                                                        throws IOException
        Get the best suitable output stream for the given combination of request and response. If the request supports gzip, the result is a GZIPOutputStream, if the request supports deflate or compress, the result will be a ZipOutputStream. If none of that matches, the regular response output stream is used
        Parameters:
        aHttpRequest - request
        aHttpResponse - Response
        Returns:
        The best matching output stream
        Throws:
        IOException - In case of IO error
        See Also:
        ResponseHelperSettings
      • isEmptyStatusCode

        public static boolean isEmptyStatusCode​(int nSC)
      • setContentLength

        public static void setContentLength​(@Nonnull
                                            jakarta.servlet.http.HttpServletResponse aHttpResponse,
                                            @Nonnegative
                                            long nContentLength)
        Set the content length of an HTTP response. If the passed content length is a valid integer, aHttpResponse.setContentLength is invoked, else the HTTP header CHttpHeader.CONTENT_LENGTH is set manually.
        Parameters:
        aHttpResponse - The response to set the content length to
        nContentLength - The content length to set
      • getResponseHeaderMap

        @Nonnull
        @ReturnsMutableCopy
        public static com.helger.commons.http.HttpHeaderMap getResponseHeaderMap​(@Nonnull
                                                                                 jakarta.servlet.http.HttpServletResponse aHttpResponse)
        Get a complete response header map as a copy.
        Parameters:
        aHttpResponse - The source HTTP response. May not be null.
        Returns:
        Never null.
        Since:
        8.7.3