Package nl.info.webdav.fromcatalina
Class RequestUtil
java.lang.Object
nl.info.webdav.fromcatalina.RequestUtil
General purpose request parsing and encoding utility methods.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringencodeCookie(jakarta.servlet.http.Cookie cookie) Encode a cookie as per RFC 2109.static StringFilter the specified message string for characters that are sensitive in HTML.static StringNormalize a relative URI path that may have relative values ("/./", "/../", and so on ) in it.static StringparseCharacterEncoding(String contentType) Parse the character encoding from the specified content type header.static jakarta.servlet.http.Cookie[]parseCookieHeader(String header) Parse a cookie header into an array of cookies according to RFC 2109.static voidparseParameters(Map<String, String[]> map, byte[] data, String encoding) Append request parameters from the specified String to the specified Map.static voidAppend request parameters from the specified String to the specified Map.static StringURLDecode(byte[] bytes) Decode and return the specified URL-encoded byte array.static StringDecode and return the specified URL-encoded byte array.static StringDecode and return the specified URL-encoded String.static StringDecode and return the specified URL-encoded String.
-
Constructor Details
-
RequestUtil
public RequestUtil()
-
-
Method Details
-
encodeCookie
Encode a cookie as per RFC 2109. The resulting string can be used as the value for aSet-Cookieheader.- Parameters:
cookie- the cookie to encode.- Returns:
- A string following RFC 2109.
-
filter
Filter the specified message string for characters that are sensitive in HTML. This avoids potential attacks caused by including JavaScript codes in the request URL that is often reported in error messages.- Parameters:
message- the message string to be filtered
-
normalize
Normalize a relative URI path that may have relative values ("/./", "/../", and so on ) in it. WARNING - This method is useful only for normalizing application-generated paths. It does not try to perform security checks for malicious input.- Parameters:
path- relative path to be normalized
-
parseCharacterEncoding
Parse the character encoding from the specified content type header. If the content type is null, or there is no explicit character encoding,nullis returned.- Parameters:
contentType- a content type header
-
parseCookieHeader
Parse a cookie header into an array of cookies according to RFC 2109.- Parameters:
header- value of an HTTP "Cookie" header
-
parseParameters
public static void parseParameters(Map<String, String[]> map, String data, String encoding) throws UnsupportedEncodingExceptionAppend request parameters from the specified String to the specified Map. It is presumed that the specified Map is not accessed from any other thread, so no synchronization is performed.IMPLEMENTATION NOTE: URL decoding is performed individually on the parsed name and value elements, rather than on the entire query string ahead of time, to properly deal with the case where the name or value includes an encoded "=" or "&" character that would otherwise be interpreted as a delimiter.
- Parameters:
map- map that accumulates the resulting parametersdata- input string containing request parameters- Throws:
IllegalArgumentException- if the data is malformedUnsupportedEncodingException
-
URLDecode
Decode and return the specified URL-encoded String. When the byte array is converted to a string, the system default character encoding is used... This may be different than some other servers.- Parameters:
str- The url-encoded string- Throws:
IllegalArgumentException- if a '%' character is not followed by a valid 2-digit hexadecimal number
-
URLDecode
Decode and return the specified URL-encoded String.- Parameters:
str- The url-encoded stringenc- The encoding to use; if null, the default encoding is used- Throws:
IllegalArgumentException- if a '%' character is not followed by a valid 2-digit hexadecimal number
-
URLDecode
Decode and return the specified URL-encoded byte array.- Parameters:
bytes- The url-encoded byte array- Throws:
IllegalArgumentException- if a '%' character is not followed by a valid 2-digit hexadecimal number
-
URLDecode
Decode and return the specified URL-encoded byte array.- Parameters:
bytes- The url-encoded byte arrayenc- The encoding to use; if null, the default encoding is used- Throws:
IllegalArgumentException- if a '%' character is not followed by a valid 2-digit hexadecimal number
-
parseParameters
public static void parseParameters(Map<String, String[]> map, byte[] data, String encoding) throws UnsupportedEncodingExceptionAppend request parameters from the specified String to the specified Map. It is presumed that the specified Map is not accessed from any other thread, so no synchronization is performed.IMPLEMENTATION NOTE: URL decoding is performed individually on the parsed name and value elements, rather than on the entire query string ahead of time, to properly deal with the case where the name or value includes an encoded "=" or "&" character that would otherwise be interpreted as a delimiter. NOTE: byte array data is modified by this method. Caller beware.
- Parameters:
map- map that accumulates the resulting parametersdata- input string containing request parametersencoding- Encoding to use for converting hex- Throws:
UnsupportedEncodingException- if the data is malformed
-