Package com.helger.servlet.response
Class UnifiedResponse
- java.lang.Object
-
- com.helger.servlet.response.UnifiedResponse
-
@NotThreadSafe public class UnifiedResponse extends Object
This class encapsulates all things required to build a HTTP response. It offer warnings and consistency checks if something is missing.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_ALLOW_CONTENT_ON_REDIRECTBy default content is not allowed on redirectstatic booleanDEFAULT_ALLOW_CONTENT_ON_STATUS_CODEBy default content is not allowed for status codesstatic EContentDispositionTypeDEFAULT_CONTENT_DISPOSITION_TYPEDefault content disposition type is Attachmentstatic booleanDEFAULT_WARN_ON_DUPLICATE_COOKIESBy default a warning is emitted on duplicate cookiesstatic intMAX_CSS_KB_FOR_IEMaximum KB a CSS file might have in IE
-
Constructor Summary
Constructors Constructor Description UnifiedResponse(com.helger.http.EHttpVersion eHttpVersion, com.helger.commons.http.EHttpMethod eHttpMethod, jakarta.servlet.http.HttpServletRequest aHttpRequest)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UnifiedResponseaddCookie(jakarta.servlet.http.Cookie aCookie)Add the passed cookie.voidaddCustomResponseHeader(String sName, String sValue)Adds a response header to the response according to the passed name and value.voidaddCustomResponseHeaders(com.helger.commons.http.HttpHeaderMap aOther)Add many custom headers at once.voidapplyToResponse(jakarta.servlet.http.HttpServletResponse aHttpResponse)com.helger.http.CacheControlBuildercacheControl()static UnifiedResponsecreateSimple(jakarta.servlet.http.HttpServletRequest aHttpRequest)Factory methodUnifiedResponsedisableCaching()A utility method that disables caching for this response.UnifiedResponseenableCaching(int nSeconds)Enable caching of this resource for the specified number of seconds.com.helger.commons.collection.impl.ICommonsOrderedMap<String,jakarta.servlet.http.Cookie>getAllCookies()CharsetgetCharset()StringgetContentDispositionFilename()EContentDispositionTypegetContentDispositionType()com.helger.commons.http.EHttpMethodgetHttpMethod()com.helger.http.EHttpVersiongetHttpVersion()protected StringgetLogPrefix()com.helger.commons.mime.IMimeTypegetMimeType()com.helger.useragent.browser.BrowserInfogetRequestBrowserInfo()protected StringgetRequestURL()intgetStatusCode()booleanhasContent()booleanhasCookies()booleanisAllowContentOnRedirect()booleanisAllowContentOnStatusCode()booleanisHttpHeaderValuesQuoteIfNecessary()booleanisHttpHeaderValuesUnified()booleanisRedirectDefined()static booleanisSilentMode()booleanisStatusCodeDefined()booleanisWarnOnDuplicateCookies()protected voidlogError(String sMsg)protected voidlogInfo(String sMsg)protected voidlogWarn(String sMsg)com.helger.commons.state.EChangeremoveAllCookies()Remove all cookies.UnifiedResponseremoveCacheControl()UnifiedResponseremoveCaching()Remove all settings and headers relevant to caching.UnifiedResponseremoveCharset()UnifiedResponseremoveContent()UnifiedResponseremoveContentDispositionFilename()Remove the current content disposition filename.UnifiedResponseremoveCookie(String sName)Remove the cookie with the specified name.com.helger.commons.state.EChangeremoveCustomResponseHeaders(String sName)Removes the response headers matching the passed name from the response.UnifiedResponseremoveETag()Remove the ETag if present.UnifiedResponseremoveExpires()UnifiedResponseremoveLastModified()UnifiedResponseremoveMimeType()UnifiedResponseremoveStrictTransportSecurity()Remove the X-Frame-Options HTTP header if it is present.UnifiedResponseremoveXFrameOptions()Remove the X-Frame-Options HTTP header if it is present.protected com.helger.commons.http.HttpHeaderMapresponseHeaderMap()UnifiedResponsesetAllowContentOnRedirect(boolean bAllowContentOnRedirect)UnifiedResponsesetAllowContentOnStatusCode(boolean bAllowContentOnStatusCode)UnifiedResponsesetAllowMimeSniffing(boolean bAllow)When specifyingfalse, this method uses a special response header to prevent certain browsers from MIME-sniffing a response away from the declared content-type.UnifiedResponsesetCacheControl(com.helger.http.CacheControlBuilder aCacheControl)UnifiedResponsesetCharset(Charset aCharset)UnifiedResponsesetContent(byte[] aContent)Set the response content.UnifiedResponsesetContent(byte[] aContent, int nOfs, int nLen)Set the response content.UnifiedResponsesetContent(com.helger.commons.io.IHasInputStream aISP)Set the response content provider.UnifiedResponsesetContentAndCharset(String sContent, Charset aCharset)Utility method to set content and charset at once.UnifiedResponsesetContentDispositionFilename(String sFilename)Set the content disposition filename for attachment download.UnifiedResponsesetContentDispositionType(EContentDispositionType eContentDispositionType)Set the content disposition type (e.g. for PDF/Excel downloads).voidsetCustomResponseHeader(String sName, String sValue)Sets a response header to the response according to the passed name and value.voidsetCustomResponseHeaders(com.helger.commons.http.HttpHeaderMap aOther)Set many custom headers at once.UnifiedResponsesetDownloadFilename(String sFilename)Utility method for setting the MimeType application/force-download and set the respective content disposition filename.UnifiedResponsesetEmptyContent()Utility method to set an empty response content.UnifiedResponsesetEnableXSSFilter(boolean bEnable)This header enables the Cross-site scripting (XSS) filter built into most recent web browsers.UnifiedResponsesetETag(String sETag)Set an ETag for the response.UnifiedResponsesetETagIfApplicable(String sETag)Set an ETag for the response if this is an HTTP/1.1 response.UnifiedResponsesetExpires(LocalDateTime aDT)UnifiedResponsesetHttpHeaderValuesQuoteIfNecessary(boolean bHttpHeaderValuesQuoteIfNecessary)Enable or disable the automatic quoting of HTTP header values.UnifiedResponsesetHttpHeaderValuesUnified(boolean bHttpHeaderValuesUnified)Enable or disable the unification of HTTP header values.UnifiedResponsesetLastModified(LocalDateTime aDT)UnifiedResponsesetMimeType(com.helger.commons.mime.IMimeType aMimeType)UnifiedResponsesetMimeTypeString(String sMimeType)UnifiedResponsesetRedirect(com.helger.commons.url.ISimpleURL aRedirectTargetUrl)UnifiedResponsesetRedirect(com.helger.commons.url.ISimpleURL aRedirectTargetUrl, ERedirectMode eRedirectMode)UnifiedResponsesetRedirect(String sRedirectTargetUrl)UnifiedResponsesetRedirect(String sRedirectTargetUrl, ERedirectMode eRedirectMode)UnifiedResponsesetRequestBrowserInfo(com.helger.useragent.browser.BrowserInfo aRequestBrowserInfo)static booleansetSilentMode(boolean bSilentMode)UnifiedResponsesetStatus(int nStatusCode)Set the status code to be returned from the response.UnifiedResponsesetStatusUnauthorized(String sAuthenticate)Special handling for returning status code 401 UNAUTHORIZED.UnifiedResponsesetStrictTransportSecurity(int nMaxAgeSeconds, boolean bIncludeSubdomains)When specifyingfalse, this method uses a special response header to prevent certain browsers from MIME-sniffing a response away from the declared content-type.UnifiedResponsesetWarnOnDuplicateCookies(boolean bWarnOnDuplicateCookies)Enable or disable warning message on duplicated cookie names.UnifiedResponsesetXFrameOptions(EXFrameOptionType eType, com.helger.commons.url.ISimpleURL aDomain)The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object> .protected voidshowRequestInfo()
-
-
-
Field Detail
-
DEFAULT_ALLOW_CONTENT_ON_REDIRECT
public static final boolean DEFAULT_ALLOW_CONTENT_ON_REDIRECT
By default content is not allowed on redirect- See Also:
- Constant Field Values
-
DEFAULT_ALLOW_CONTENT_ON_STATUS_CODE
public static final boolean DEFAULT_ALLOW_CONTENT_ON_STATUS_CODE
By default content is not allowed for status codes- See Also:
- Constant Field Values
-
DEFAULT_CONTENT_DISPOSITION_TYPE
public static final EContentDispositionType DEFAULT_CONTENT_DISPOSITION_TYPE
Default content disposition type is Attachment
-
DEFAULT_WARN_ON_DUPLICATE_COOKIES
public static final boolean DEFAULT_WARN_ON_DUPLICATE_COOKIES
By default a warning is emitted on duplicate cookies- Since:
- 6.0.5
- See Also:
- Constant Field Values
-
MAX_CSS_KB_FOR_IE
public static final int MAX_CSS_KB_FOR_IE
Maximum KB a CSS file might have in IE- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UnifiedResponse
public UnifiedResponse(@Nonnull com.helger.http.EHttpVersion eHttpVersion, @Nonnull com.helger.commons.http.EHttpMethod eHttpMethod, @Nonnull jakarta.servlet.http.HttpServletRequest aHttpRequest)
Constructor- Parameters:
eHttpVersion- HTTP version of this request (1.0 or 1.1)eHttpMethod- HTTP method of this request (GET, POST, ...)aHttpRequest- The main HTTP request
-
-
Method Detail
-
isSilentMode
public static boolean isSilentMode()
-
setSilentMode
public static boolean setSilentMode(boolean bSilentMode)
-
showRequestInfo
protected final void showRequestInfo()
-
getHttpVersion
@Nonnull public final com.helger.http.EHttpVersion getHttpVersion()
- Returns:
- The HTTP version of the request. Never
null.
-
getHttpMethod
@Nonnull public final com.helger.commons.http.EHttpMethod getHttpMethod()
- Returns:
- The HTTP method of the request. Never
null.
-
getRequestBrowserInfo
@Nullable public final com.helger.useragent.browser.BrowserInfo getRequestBrowserInfo()
- Returns:
- The browser info of the request. Never
null.
-
setRequestBrowserInfo
@Nonnull public final UnifiedResponse setRequestBrowserInfo(@Nullable com.helger.useragent.browser.BrowserInfo aRequestBrowserInfo)
-
isAllowContentOnRedirect
public final boolean isAllowContentOnRedirect()
- Returns:
trueif content is allowed even if a redirect is present.
-
setAllowContentOnRedirect
@Nonnull public final UnifiedResponse setAllowContentOnRedirect(boolean bAllowContentOnRedirect)
-
isAllowContentOnStatusCode
public final boolean isAllowContentOnStatusCode()
- Returns:
trueif content is allowed even if a status code is present.
-
setAllowContentOnStatusCode
@Nonnull public final UnifiedResponse setAllowContentOnStatusCode(boolean bAllowContentOnStatusCode)
-
setCharset
@Nonnull public final UnifiedResponse setCharset(@Nonnull Charset aCharset)
-
removeCharset
@Nonnull public final UnifiedResponse removeCharset()
-
getMimeType
@Nullable public final com.helger.commons.mime.IMimeType getMimeType()
-
setMimeType
@Nonnull public final UnifiedResponse setMimeType(@Nonnull com.helger.commons.mime.IMimeType aMimeType)
-
setMimeTypeString
@Nonnull public final UnifiedResponse setMimeTypeString(@Nonnull @Nonempty String sMimeType)
-
removeMimeType
@Nonnull public final UnifiedResponse removeMimeType()
-
hasContent
public final boolean hasContent()
- Returns:
trueif a content was already set,falseif not.
-
setEmptyContent
@Nonnull public final UnifiedResponse setEmptyContent()
Utility method to set an empty response content.- Returns:
- this
-
setContentAndCharset
@Nonnull public final UnifiedResponse setContentAndCharset(@Nonnull String sContent, @Nonnull Charset aCharset)
Utility method to set content and charset at once.- Parameters:
sContent- The response content string. May not benull.aCharset- The charset to use. May not benull.- Returns:
- this
-
setContent
@Nonnull public final UnifiedResponse setContent(@Nonnull byte[] aContent)
Set the response content. To return an empty response pass in a new empty array, but notnull.- Parameters:
aContent- The content to be returned. Is not copied inside! May not benullbut maybe empty.- Returns:
- this
-
setContent
@Nonnull public final UnifiedResponse setContent(@Nonnull byte[] aContent, @Nonnegative int nOfs, @Nonnegative int nLen)
Set the response content. To return an empty response pass in a new empty array, but notnull.- Parameters:
aContent- The content to be returned. Is not copied inside! May not benullbut maybe empty.nOfs- The content offset to start at. Must be ≥ 0.nLen- The content length to use. Must be ≥ 0 and ≤ than the content length!- Returns:
- this
-
setContent
@Nonnull public final UnifiedResponse setContent(@Nonnull com.helger.commons.io.IHasInputStream aISP)
Set the response content provider.- Parameters:
aISP- The content provider to be used. May not benull.- Returns:
- this
-
removeContent
@Nonnull public final UnifiedResponse removeContent()
-
setExpires
@Nonnull public final UnifiedResponse setExpires(@Nonnull LocalDateTime aDT)
-
removeExpires
@Nonnull public final UnifiedResponse removeExpires()
-
setLastModified
@Nonnull public final UnifiedResponse setLastModified(@Nonnull LocalDateTime aDT)
-
removeLastModified
@Nonnull public final UnifiedResponse removeLastModified()
-
setETag
@Nonnull public final UnifiedResponse setETag(@Nonnull @Nonempty String sETag)
Set an ETag for the response. The ETag must be a quoted value (being surrounded by double quotes).- Parameters:
sETag- The quoted ETag to be set. May neither benullnor empty.- Returns:
- this
-
setETagIfApplicable
@Nonnull public final UnifiedResponse setETagIfApplicable(@Nonnull @Nonempty String sETag)
Set an ETag for the response if this is an HTTP/1.1 response. HTTP/1.0 does not support ETags. The ETag must be a quoted value (being surrounded by double quotes).- Parameters:
sETag- The quoted ETag to be set. May neither benullnor empty.- Returns:
- this
-
removeETag
@Nonnull public final UnifiedResponse removeETag()
Remove the ETag if present.- Returns:
- this
-
setContentDispositionType
@Nonnull public final UnifiedResponse setContentDispositionType(@Nonnull EContentDispositionType eContentDispositionType)
Set the content disposition type (e.g. for PDF/Excel downloads). The default isDEFAULT_CONTENT_DISPOSITION_TYPE. This value is only used if a content disposition filename is defined.- Parameters:
eContentDispositionType- The content disposition type to be used. May not benull.- Returns:
- this
- See Also:
setContentDispositionFilename(String)
-
getContentDispositionType
@Nonnull public final EContentDispositionType getContentDispositionType()
- Returns:
- The current content disposition type. Never
null. Default isDEFAULT_CONTENT_DISPOSITION_TYPE.
-
setContentDispositionFilename
@Nonnull public final UnifiedResponse setContentDispositionFilename(@Nonnull @Nonempty String sFilename)
Set the content disposition filename for attachment download.- Parameters:
sFilename- The filename for attachment download to use. May neither benullnor empty.- Returns:
- this
- See Also:
removeContentDispositionFilename()
-
getContentDispositionFilename
@Nullable public final String getContentDispositionFilename()
- Returns:
- The current content disposition filename. May be
nullif not set.
-
removeContentDispositionFilename
@Nonnull public final UnifiedResponse removeContentDispositionFilename()
Remove the current content disposition filename. This method can be called if a filename is set or not.- Returns:
- this
-
setDownloadFilename
@Nonnull public final UnifiedResponse setDownloadFilename(@Nonnull @Nonempty String sFilename)
Utility method for setting the MimeType application/force-download and set the respective content disposition filename.- Parameters:
sFilename- The filename to be used.- Returns:
- this
-
setCacheControl
@Nonnull public final UnifiedResponse setCacheControl(@Nonnull com.helger.http.CacheControlBuilder aCacheControl)
-
cacheControl
@Nullable @ReturnsMutableObject public final com.helger.http.CacheControlBuilder cacheControl()
-
removeCacheControl
@Nonnull public final UnifiedResponse removeCacheControl()
-
responseHeaderMap
@Nonnull @ReturnsMutableObject protected final com.helger.commons.http.HttpHeaderMap responseHeaderMap()
- Returns:
- The non-
nullheader map.
-
removeCaching
@Nonnull public final UnifiedResponse removeCaching()
Remove all settings and headers relevant to caching.- Returns:
- this for chaining
-
disableCaching
@Nonnull public final UnifiedResponse disableCaching()
A utility method that disables caching for this response.- Returns:
- this
-
enableCaching
@Nonnull public final UnifiedResponse enableCaching(@Nonnegative int nSeconds)
Enable caching of this resource for the specified number of seconds.- Parameters:
nSeconds- The number of seconds caching is allowed. Must be > 0.- Returns:
- this
-
isStatusCodeDefined
public final boolean isStatusCodeDefined()
- Returns:
trueif a status code is defined,falseif not.
-
getStatusCode
public final int getStatusCode()
- Returns:
- The HTTP status code defined or
CGlobal.ILLEGAL_UINTif undefined. - See Also:
isStatusCodeDefined()
-
setStatus
@Nonnull public final UnifiedResponse setStatus(@Nonnegative int nStatusCode)
Set the status code to be returned from the response.- Parameters:
nStatusCode- The status code to be set. Must be a valid HTTP response code.- Returns:
- this
-
setStatusUnauthorized
@Nonnull public final UnifiedResponse setStatusUnauthorized(@Nullable String sAuthenticate)
Special handling for returning status code 401 UNAUTHORIZED.- Parameters:
sAuthenticate- The string to be used for theCHttpHeader.WWW_AUTHENTICATEresponse header. May benullor empty.- Returns:
- this
-
isRedirectDefined
public final boolean isRedirectDefined()
-
setRedirect
@Nonnull public final UnifiedResponse setRedirect(@Nonnull com.helger.commons.url.ISimpleURL aRedirectTargetUrl)
-
setRedirect
@Nonnull public final UnifiedResponse setRedirect(@Nonnull com.helger.commons.url.ISimpleURL aRedirectTargetUrl, @Nonnull ERedirectMode eRedirectMode)
-
setRedirect
@Nonnull public final UnifiedResponse setRedirect(@Nonnull @Nonempty String sRedirectTargetUrl)
-
setRedirect
@Nonnull public final UnifiedResponse setRedirect(@Nonnull @Nonempty String sRedirectTargetUrl, @Nonnull ERedirectMode eRedirectMode)
-
isWarnOnDuplicateCookies
public final boolean isWarnOnDuplicateCookies()
- Returns:
trueif warning on duplicated cookies is enabled,falseif it is disabled.- Since:
- 6.0.5
-
setWarnOnDuplicateCookies
@Nonnull public final UnifiedResponse setWarnOnDuplicateCookies(boolean bWarnOnDuplicateCookies)
Enable or disable warning message on duplicated cookie names.- Parameters:
bWarnOnDuplicateCookies-trueto enable warnings,falseto disable them.- Returns:
- this
- Since:
- 6.0.5
-
addCookie
@Nonnull public final UnifiedResponse addCookie(@Nonnull jakarta.servlet.http.Cookie aCookie)
Add the passed cookie.- Parameters:
aCookie- The cookie to be added. May not benull.- Returns:
- this
-
removeCookie
@Nonnull public final UnifiedResponse removeCookie(@Nullable String sName)
Remove the cookie with the specified name.- Parameters:
sName- The name of the cookie to be removed. May benull.- Returns:
- this
-
removeAllCookies
@Nonnull public final com.helger.commons.state.EChange removeAllCookies()
Remove all cookies.- Returns:
EChange.CHANGEDif at least one cookie was removed.- Since:
- 6.0.5
-
hasCookies
public final boolean hasCookies()
- Returns:
trueif at least one cookie is present.- Since:
- 6.0.5
-
getAllCookies
@Nonnull @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsOrderedMap<String,jakarta.servlet.http.Cookie> getAllCookies()
- Returns:
- A copy of all contained cookies. Never
nullbut maybe empty. - Since:
- 6.0.5
-
isHttpHeaderValuesUnified
public final boolean isHttpHeaderValuesUnified()
- Returns:
trueif HTTP header values will be unified,falseif not.- Since:
- 9.1.4
- See Also:
UnifiedResponseDefaultSettings.isHttpHeaderValuesUnified()
-
setHttpHeaderValuesUnified
@Nonnull public final UnifiedResponse setHttpHeaderValuesUnified(boolean bHttpHeaderValuesUnified)
Enable or disable the unification of HTTP header values.- Parameters:
bHttpHeaderValuesUnified-trueto enable it,falseto disable it.- Returns:
- this for chaining
- Since:
- 9.1.4
-
isHttpHeaderValuesQuoteIfNecessary
public final boolean isHttpHeaderValuesQuoteIfNecessary()
- Returns:
trueif HTTP header values will be unified and quoted if necessary,falseif not.- Since:
- 9.1.4
- See Also:
UnifiedResponseDefaultSettings.isHttpHeaderValuesQuoteIfNecessary()
-
setHttpHeaderValuesQuoteIfNecessary
@Nonnull public final UnifiedResponse setHttpHeaderValuesQuoteIfNecessary(boolean bHttpHeaderValuesQuoteIfNecessary)
Enable or disable the automatic quoting of HTTP header values. This only takes effect, if the unification is enabled.- Parameters:
bHttpHeaderValuesQuoteIfNecessary-trueto enable it,falseto disable it.- Returns:
- this for chaining
- Since:
- 9.1.4
- See Also:
setHttpHeaderValuesUnified(boolean)
-
setAllowMimeSniffing
@Nonnull public final UnifiedResponse setAllowMimeSniffing(boolean bAllow)
When specifyingfalse, this method uses a special response header to prevent certain browsers from MIME-sniffing a response away from the declared content-type. When passingtrue, that header is removed.- Parameters:
bAllow- Whether or not sniffing should be allowed (default istrue).- Returns:
- this
-
setEnableXSSFilter
@Nonnull public final UnifiedResponse setEnableXSSFilter(boolean bEnable)
This header enables the Cross-site scripting (XSS) filter built into most recent web browsers. It's usually enabled by default anyway, so the role of this header is to re-enable the filter for this particular website if it was disabled by the user. This header is supported in IE 8+, and in Chrome (not sure which versions). The anti-XSS filter was added in Chrome 4. Its unknown if that version honored this header.- Parameters:
bEnable-trueto enable the header,falseto disable it.- Returns:
- this
- Since:
- 6.0.5
-
setStrictTransportSecurity
@Nonnull public final UnifiedResponse setStrictTransportSecurity(int nMaxAgeSeconds, boolean bIncludeSubdomains)
When specifyingfalse, this method uses a special response header to prevent certain browsers from MIME-sniffing a response away from the declared content-type. When passingtrue, that header is removed.- Parameters:
nMaxAgeSeconds- number of seconds, after the reception of the STS header field, during which the UA regards the host (from whom the message was received) as a Known HSTS Host.bIncludeSubdomains- if enabled, this signals the UA that the HSTS Policy applies to this HSTS Host as well as any sub-domains of the host's domain name.- Returns:
- this
-
removeStrictTransportSecurity
@Nonnull public final UnifiedResponse removeStrictTransportSecurity()
Remove the X-Frame-Options HTTP header if it is present.- Returns:
- this
- Since:
- 6.0.5
-
setXFrameOptions
@Nonnull public final UnifiedResponse setXFrameOptions(@Nonnull EXFrameOptionType eType, @Nullable com.helger.commons.url.ISimpleURL aDomain)
The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object> . Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites. Example:X-Frame-Options: DENY X-Frame-Options: SAMEORIGIN X-Frame-Options: ALLOW-FROM https://example.com/
- Parameters:
eType- The X-Frame-Options type to be set. May not benull.aDomain- The domain URL to be used in "ALLOW-FROM". May benullfor the other cases.- Returns:
- this
- Since:
- 6.0.5
-
removeXFrameOptions
@Nonnull public final UnifiedResponse removeXFrameOptions()
Remove the X-Frame-Options HTTP header if it is present.- Returns:
- this
- Since:
- 6.0.5
-
addCustomResponseHeader
public final void addCustomResponseHeader(@Nonnull @Nonempty String sName, @Nonnull @Nonempty String sValue)
Adds a response header to the response according to the passed name and value. If an existing header with the same is present, the value is added to the list so that the header is emitted more than once.
ATTENTION: You should only use the APIs thatUnifiedResponsedirectly offers. Use this method only in emergency and make sure you validate the header field and allowed value!- Parameters:
sName- Name of the header. May neither benullnor empty.sValue- Value of the header. May neither benullnor empty.
-
addCustomResponseHeaders
public final void addCustomResponseHeaders(@Nullable com.helger.commons.http.HttpHeaderMap aOther)
Add many custom headers at once.- Parameters:
aOther- The headers to be added. May benull.
-
setCustomResponseHeader
public final void setCustomResponseHeader(@Nonnull @Nonempty String sName, @Nonnull @Nonempty String sValue)
Sets a response header to the response according to the passed name and value. An existing header entry with the same name is overridden.
ATTENTION: You should only use the APIs thatUnifiedResponsedirectly offers. Use this method only in emergency and make sure you validate the header field and allowed value!- Parameters:
sName- Name of the header. May neither benullnor empty.sValue- Value of the header. May neither benullnor empty.
-
setCustomResponseHeaders
public final void setCustomResponseHeaders(@Nullable com.helger.commons.http.HttpHeaderMap aOther)
Set many custom headers at once. All existing headers are unconditionally removed.- Parameters:
aOther- The headers to be set. May benull.
-
removeCustomResponseHeaders
@Nonnull public final com.helger.commons.state.EChange removeCustomResponseHeaders(@Nonnull @Nonempty String sName)
Removes the response headers matching the passed name from the response.
ATTENTION: You should only use the APIs thatUnifiedResponsedirectly offers. Use this method only in emergency and make sure you validate the header field and allowed value!- Parameters:
sName- Name of the header to be removed. May neither benullnor empty.- Returns:
EChange.CHANGEDin header was removed.
-
applyToResponse
public final void applyToResponse(@Nonnull jakarta.servlet.http.HttpServletResponse aHttpResponse) throws IOException
- Throws:
IOException
-
createSimple
@Nonnull public static UnifiedResponse createSimple(@Nonnull jakarta.servlet.http.HttpServletRequest aHttpRequest)
Factory method- Parameters:
aHttpRequest- The main HTTP request. May not benull.- Returns:
- New
UnifiedResponse. Nevernull. - Since:
- 8.8.0
-
-