Package net.shibboleth.shared.servlet
Class HttpServletSupport
java.lang.Object
net.shibboleth.shared.servlet.HttpServletSupport
Utilities for working with HTTP Servlet requests and responses.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddNoCacheHeaders(HttpServletResponse response) Adds Cache-Control and Pragma headers meant to disable caching.static URIgetFullRequestURI(HttpServletRequest request) Gets the URL that was requested to generate this request.static List<Locale.LanguageRange>getLanguageRange(HttpServletRequest request) Return theLocale.LanguageRangeassociated with this request.static StringgetRemoteAddr(ServletRequest request) Gets the sanitized form of the result ofServletRequest.getRemoteAddr().static StringGets the request URI as returned byHttpServletRequest.getRequestURI()but without the servlet context path.static voidsetContentType(HttpServletResponse response, String contentType) Sets the MIME content type of the response.static voidsetUTF8Encoding(HttpServletResponse response) Sets the character encoding of the transport to UTF-8.static booleanvalidateContentType(HttpServletRequest request, Set<MediaType> validTypes, boolean noContentTypeIsValid, boolean isOneOfStrategy) Validate the Content-Type of the specified request.
-
Field Details
-
LOG
@Nonnull private static final org.slf4j.Logger LOGLog.
-
-
Constructor Details
-
HttpServletSupport
private HttpServletSupport()Constructor.
-
-
Method Details
-
addNoCacheHeaders
Adds Cache-Control and Pragma headers meant to disable caching.- Parameters:
response- transport to add headers to
-
setUTF8Encoding
Sets the character encoding of the transport to UTF-8.- Parameters:
response- transport to set character encoding type
-
setContentType
public static void setContentType(@Nonnull HttpServletResponse response, @Nullable String contentType) Sets the MIME content type of the response.- Parameters:
response- the transport to set content type oncontentType- the content type to set
-
getRequestPathWithoutContext
Gets the request URI as returned byHttpServletRequest.getRequestURI()but without the servlet context path.- Parameters:
request- request to get the URI from- Returns:
- constructed URI
-
getFullRequestURI
Gets the URL that was requested to generate this request. This includes the scheme, host, port, path, and query string.- Parameters:
request- current request- Returns:
- URL that was requested to generate this request
-
validateContentType
public static boolean validateContentType(@Nonnull HttpServletRequest request, @Nonnull Set<MediaType> validTypes, boolean noContentTypeIsValid, boolean isOneOfStrategy) Validate the Content-Type of the specified request.Two strategies are supported for evaluating the request's parsed content type:
-
If isOneOfStrategy is true, then the
MediaTypeparsed from the request is compared to each of the specified valid types viaMediaType.is(MediaType). If any pass, the type is considered valid. This allows use of MediaType's support for wildcard and parameter evaluation. -
If isOneOfStrategy is false, then the
MediaTypeparsed from the request is stripped of its parameters, as is each of the valid types. Then a simple evaluation is done that the request type is equal to one of the passed types. In this case, only literal types and subtypes should be passed as valid types; wildcards should not be used.
- Parameters:
request- the request to be validatedvalidTypes- the set of valid media typesnoContentTypeIsValid- flag whether the case of a missing/empty Content-Type header is considered validisOneOfStrategy- flag for the strategy used in the validation (see above for details)- Returns:
- true if the content type is valid, false if not
-
If isOneOfStrategy is true, then the
-
getLanguageRange
@Nonnull @Unmodifiable @NotLive public static List<Locale.LanguageRange> getLanguageRange(@Nonnull HttpServletRequest request) Return theLocale.LanguageRangeassociated with this request. This is more up to date thanServletRequest.getLocales().- Parameters:
request- the request to process- Returns:
- The range
-
getRemoteAddr
Gets the sanitized form of the result ofServletRequest.getRemoteAddr().This routine accounts for variability in the format of the returned address string, in particular the incorrect use of brackets around IPv6 addresses, a form intended to be used when expressing addresses as hostnames, not as bare addresses.
- Parameters:
request- servlet request- Returns:
- sanitized address string
-