Package net.i2p.servlet.util
Class ServletUtil
java.lang.Object
net.i2p.servlet.util.ServletUtil
Simple utilities for servlets.
Consolidated from i2psnark, susimail, and routerconsole
- Since:
- 0.9.33
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallowOrigin(HttpServletRequest request) Validate Origin header for POST requests.static booleanallowOrigin(Request request) Validate Origin header for POST requests.static booleanThe intent here is to return true for phones but false for big tablets? But not consistent.static booleanisSmallBrowser(String ua) static booleanisTextBrowser(String ua) static StringSanitize an encoded String from getQueryString().static StringTruncate a String.
-
Method Details
-
isSmallBrowser
- Parameters:
ua- User-Agent string, non-null- Returns:
- true if a text-mode or mobile browser
-
isTextBrowser
- Parameters:
ua- User-Agent string, non-null- Returns:
- true if a text-mode browser
-
isMobileBrowser
The intent here is to return true for phones but false for big tablets? But not consistent.- Parameters:
ua- User-Agent string, non-null- Returns:
- true if a mobile browser
-
truncate
Truncate a String. Same as s.substring(0, len) except that it won't split a surrogate pair or at a ZWJ.- Parameters:
s- non-nulllen- greater than zero- Returns:
- s if shorter; s.substring(0, len) if the char at len-1 is not a high surrogate or the char at len-1 or len is not a zero-width joiner; s.substring(0, len+1 or len+2) if it is
- Since:
- 0.9.33
-
sanitizeQuery
Sanitize an encoded String from getQueryString(). Does not decode.- Parameters:
s- may be null- Returns:
- s or null if s was null or s contained any problematic characters
- Since:
- 0.9.70
-
allowOrigin
Validate Origin header for POST requests. Allows requests with matching Origin (same-origin), or no Origin header. Rejects cross-origin POST requests to prevent CSRF attacks. Ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Origin- Parameters:
request- the HTTP request- Returns:
- true if allowed
- Since:
- 0.9.70
-
allowOrigin
Validate Origin header for POST requests. Allows requests with matching Origin (same-origin), or no Origin header. Rejects cross-origin POST requests to prevent CSRF attacks. Ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Origin- Parameters:
request- the HTTP request- Returns:
- true if allowed
- Since:
- 0.9.70
-