Package com.helger.servlet.response
Class ResponseHelper
- java.lang.Object
-
- com.helger.servlet.response.ResponseHelper
-
@Immutable public final class ResponseHelper extends Object
Misc. helper methods onHttpServletResponseobjects.
Consider using theUnifiedResponsefor easy and consistent HTTP response handling.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidfinishReponseOutputStream(OutputStream aOS)static OutputStreamgetBestSuitableOutputStream(jakarta.servlet.http.HttpServletRequest aHttpRequest, jakarta.servlet.http.HttpServletResponse aHttpResponse)Get the best suitable output stream for the given combination of request and response.static EResponseStreamTypegetBestSuitableOutputStreamType(jakarta.servlet.http.HttpServletRequest aHttpRequest)Determine the best suitable output stream type for the given request without actually modifying response data.static com.helger.commons.http.HttpHeaderMapgetResponseHeaderMap(jakarta.servlet.http.HttpServletResponse aHttpResponse)Get a complete response header map as a copy.static booleanisEmptyStatusCode(int nSC)static voidsetContentLength(jakarta.servlet.http.HttpServletResponse aHttpResponse, long nContentLength)Set the content length of an HTTP response.
-
-
-
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 aEResponseStreamType.GZIP, if the request supports deflate or compress, the result will be aEResponseStreamType.DEFLATE. If none of that matches, the regular valueEResponseStreamType.PLAINwill 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 aGZIPOutputStream, if the request supports deflate or compress, the result will be aZipOutputStream. If none of that matches, the regular response output stream is used- Parameters:
aHttpRequest- requestaHttpResponse- Response- Returns:
- The best matching output stream
- Throws:
IOException- In case of IO error- See Also:
ResponseHelperSettings
-
finishReponseOutputStream
public static void finishReponseOutputStream(@Nonnull OutputStream aOS) throws IOException
- Throws:
IOException
-
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.setContentLengthis invoked, else the HTTP headerCHttpHeader.CONTENT_LENGTHis set manually.- Parameters:
aHttpResponse- The response to set the content length tonContentLength- 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 benull.- Returns:
- Never
null. - Since:
- 8.7.3
-
-