Package com.groiss.servlet
Class HttpUtils
java.lang.Object
com.groiss.servlet.HttpUtils
Utility class for dealing with special cases in the area of the HTTP protocol.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
cookieName
(String suffix) Generate a cookie name by prepending the serverid and _ to the suffix.static String
static Cookie
getCookie
(HttpServletRequest req, String suffix) return the cookie from the request.static String
getCookieValue
(HttpServletRequest req, String suffix) Returns a cookie value.static String
Returns the "real" remote address of a HttpServletRequest.static StringBuilder
static Cookie
Generate a new Cookie.static Cookie
newHttpOnlyCookie
(String suffix, String value) Generate a new HTTP-only Cookie.static void
Set the security attribute of a cookie.static void
Deprecated.
-
Method Details
-
setNoCache
Deprecated.UseServletUtils.setNoCache(HttpServletResponse)
instead.Set response to no-cache. Note that you have to call this method before data is written (getWriter() or getOutputStream() is called).- Parameters:
res
- the HTTP-response
-
cookieName
Generate a cookie name by prepending the serverid and _ to the suffix.- Parameters:
suffix
-- Returns:
- <serverid>_<suffix>
-
newCookie
Generate a new Cookie. The cookie name is generated from the suffix viacookieName(String)
.the Path is set to the servlet context path and the maxAge to -1.
Please be sure to set httpOnly for the cookie via
Cookie.setHttpOnly(boolean)
if appropriate, or usenewHttpOnlyCookie(String, String)
directly.- Parameters:
suffix
- the suffix of the cookie namevalue
- the cookie value- Returns:
-
newHttpOnlyCookie
Generate a new HTTP-only Cookie. The cookie name is generated from the suffix viacookieName(String)
.- Parameters:
suffix
- the suffix of the cookie namevalue
- the cookie value- Returns:
-
setCookieSecurity
Set the security attribute of a cookie. Depends on the request and on the configuration property "httpd.cookie.forceSecure".
The security attribute of the cookie will be set to true if req.isSecure() it true or if the property httpd.cookie.forceSecure is true. Otherwise the security attribute will be set to false.- Parameters:
c
- the cookiereq
- the request
-
getCookie
return the cookie from the request.- Parameters:
req
-suffix
- the name part of the cookie that follows the server id.- Returns:
- the cookie or null if no such cookie
-
getCookieValue
Returns a cookie value.- Parameters:
req
-suffix
- the name part of the cookie that follows the server id.- Returns:
- the cookie value or null if no such cookie.
-
getRemoteAddress
Returns the "real" remote address of a HttpServletRequest.- Parameters:
req
-- Returns:
- the leftmost component of the X-Forwarded-For header field, if it exists, req.getRemoteAddr() if not.
-
extractIP
-
getRequestURLContext
-
ServletUtils.setNoCache(HttpServletResponse)
instead.