public class HttpUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CACHE_CONTROL_HEADER_NAME |
static int |
DEFAULT_HTTP_PORT |
static int |
DEFAULT_HTTPS_PORT |
static String |
EXPIRES_HEADER_NAME |
static String |
HTTP_SCHEME |
static String |
HTTPS_SCHEME |
static String |
PRAGMA_HEADER_NAME |
| Constructor and Description |
|---|
HttpUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addValue(String key,
Object value,
org.springframework.util.MultiValueMap<String,String> params)
Adds a param value to a params map.
|
static void |
addValues(String key,
Collection<String> values,
org.springframework.util.MultiValueMap<String,String> params)
Adds a collection of param values to a params map.
|
static void |
addValues(String key,
String[] values,
org.springframework.util.MultiValueMap<String,String> params)
Adds an array of param values to a params map.
|
static Map<String,String> |
createCookiesMap(javax.servlet.http.HttpServletRequest request)
Creates a map from the cookies in the specified request.
|
static Map<String,Object> |
createHeadersMap(javax.servlet.http.HttpServletRequest request)
Creates a map from the headers in the specified request.
|
static Map<String,Object> |
createRequestAttributesMap(javax.servlet.http.HttpServletRequest request)
Creates a map from the request attributes in the specified request.
|
static Map<String,Object> |
createRequestParamsMap(javax.servlet.http.HttpServletRequest request)
Creates a map from the parameters in the specified request.
|
static Map<String,Object> |
createSessionMap(javax.servlet.http.HttpServletRequest request)
Creates a map from the session attributes in the specified request.
|
static void |
disableCaching(javax.servlet.http.HttpServletResponse response)
Disable caching in the client.
|
static StringBuilder |
getBaseRequestUrl(javax.servlet.http.HttpServletRequest request,
boolean forceHttps)
Returns the portion from the URL that includes the scheme, server name and port number, without the server
path.
|
static javax.servlet.http.Cookie |
getCookie(String name,
javax.servlet.http.HttpServletRequest request)
Returns the cookie with the given name for the given request
|
static String |
getCookieValue(String name,
javax.servlet.http.HttpServletRequest request)
Returns the cookie value with the given name for the given request
|
static String |
getFullRequestUri(javax.servlet.http.HttpServletRequest request,
boolean includeQueryString)
Returns the full request URI, including scheme, server name, port number and server path.
|
static String |
getFullUrl(javax.servlet.http.HttpServletRequest request,
String relativeUrl)
Returns the full URL for the relative URL based in the specified request.
|
static org.springframework.util.MultiValueMap<String,String> |
getParamsFromQueryString(String queryString)
Returns a map with the extracted parameters from the specified query string.
|
static String |
getQueryStringFromParams(org.springframework.util.MultiValueMap<String,String> queryParams)
Builds a query string from the specified params.
|
static String |
getQueryStringFromParams(org.springframework.util.MultiValueMap<String,String> queryParams,
boolean encodeValues)
Builds a query string from the specified params.
|
static String |
getQueryStringFromParams(org.springframework.util.MultiValueMap<String,String> queryParams,
String charset,
boolean encodeValues)
Builds a query string from the specified params.
|
static String |
getRequestUriWithoutContextPath(javax.servlet.http.HttpServletRequest request)
Returns the request URI without the context path.
|
public static final String HTTP_SCHEME
public static final String HTTPS_SCHEME
public static final int DEFAULT_HTTP_PORT
public static final int DEFAULT_HTTPS_PORT
public static final String PRAGMA_HEADER_NAME
public static final String CACHE_CONTROL_HEADER_NAME
public static final String EXPIRES_HEADER_NAME
public static StringBuilder getBaseRequestUrl(javax.servlet.http.HttpServletRequest request, boolean forceHttps)
request - the request object used to build the base URLforceHttps - if HTTPS should be enforcedpublic static String getFullUrl(javax.servlet.http.HttpServletRequest request, String relativeUrl)
request - the request object used to build the base URLrelativeUrl - the relative URLpublic static final String getRequestUriWithoutContextPath(javax.servlet.http.HttpServletRequest request)
request - the request where to get the URI frompublic static final String getFullRequestUri(javax.servlet.http.HttpServletRequest request, boolean includeQueryString)
request - the request object used to build the URIincludeQueryString - if the query string should be appended to the URIpublic static javax.servlet.http.Cookie getCookie(String name, javax.servlet.http.HttpServletRequest request)
name - the name of the cookierequest - the request where to extract the request frompublic static String getCookieValue(String name, javax.servlet.http.HttpServletRequest request)
name - the name of the cookierequest - the request where to extract the request frompublic static void addValue(String key, Object value, org.springframework.util.MultiValueMap<String,String> params)
key - the param keyvalue - the param valueparams - the params mappublic static void addValues(String key, Collection<String> values, org.springframework.util.MultiValueMap<String,String> params)
key - the param keyvalues - the collection of param valuesparams - the params mappublic static void addValues(String key, String[] values, org.springframework.util.MultiValueMap<String,String> params)
key - the param keyvalues - the array of param valuesparams - the params mappublic static org.springframework.util.MultiValueMap<String,String> getParamsFromQueryString(String queryString)
queryString - the query string to extract the params frompublic static String getQueryStringFromParams(org.springframework.util.MultiValueMap<String,String> queryParams)
queryParams - the params to build the query string withpublic static String getQueryStringFromParams(org.springframework.util.MultiValueMap<String,String> queryParams, boolean encodeValues)
encodeValues is true. UTF-8 is used as the encoding charset.queryParams - the params to build the query string withencodeValues - if the param values should be encodedpublic static String getQueryStringFromParams(org.springframework.util.MultiValueMap<String,String> queryParams, String charset, boolean encodeValues) throws UnsupportedEncodingException
encodeValues is true.queryParams - the params to build the query string withcharset - the charset to use for URL encodingencodeValues - if the param values should be encodedUnsupportedEncodingExceptionpublic static Map<String,Object> createRequestParamsMap(javax.servlet.http.HttpServletRequest request)
request - the requestpublic static Map<String,Object> createRequestAttributesMap(javax.servlet.http.HttpServletRequest request)
request - the requestpublic static Map<String,Object> createHeadersMap(javax.servlet.http.HttpServletRequest request)
request - the requestpublic static Map<String,String> createCookiesMap(javax.servlet.http.HttpServletRequest request)
request - the requestpublic static Map<String,Object> createSessionMap(javax.servlet.http.HttpServletRequest request)
request - the requestpublic static void disableCaching(javax.servlet.http.HttpServletResponse response)
response - the response to add the headers for disabling caching.Copyright © 2020 CrafterCMS. All rights reserved.