java.lang.Object
edu.iu.IuWebUtils
Provides useful utility methods for low-level web client and server
interactions.
-
Method Summary
Modifier and TypeMethodDescription(package private) static boolean
alpha
(char c) ALPHA = %x41-5A / %x61-7A(package private) static int
BWS = OWS(package private) static int
comment = "(" *( ctext / quoted-pair / comment ) ")"static String
createChallenge
(String scheme, Map<String, String> params) Creates an authentication challenge sending to a client via the WWW-Authenticate header.static String
createQueryString
(Map<String, ? extends Iterable<String>> params) Creates a query string from a map.(package private) static boolean
ctext
(char c) ctext = HTAB / SP / %x21-27 / %x2A-5B / %x5D-7E / obs-textstatic String
describeStatus
(int statusCode) Describes an HTTP status code.(package private) static boolean
digit
(char c) DIGIT = %x30-39static InetAddress
getInetAddress
(String hostname) Resolves and caches theIP address
for a host name.static boolean
isInetAddressInRange
(InetAddress address, String range) Determines whether or not an IP address is included in a CIDR range.static boolean
static boolean
isVisibleAscii
(String s, int minLength) Determines whether or not a string is composed entirely of non-whitespace visible ASCII characters, and at least minLength characters, but no longer than 1024.static String
normalizeHeaderName
(String headerName) Validates and normalizes case for an HTTP header name.(package private) static boolean
obsText
(char c) obs-text = %x80-FFstatic Iterator
<IuWebAuthenticationChallenge> parseAuthenticateHeader
(String wwwAuthenticate) Parses challenge parameters from a WWW-Authenticate header.parseHeader
(String headerValue) Parses a header value composed of key/value pairs separated by semicolon ';'.parseQueryString
(String queryString) Parses a query string.(package private) static int
product = token [ "/" product-version ](package private) static boolean
qdtext
(char c) qdtext = HTAB / SP / "!" / %x23-5B / %x5D-7E / obs-text(package private) static int
quotedPair
(String s, int pos) quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )(package private) static int
quotedString
(String s, int start) quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE(package private) static int
1*SP(package private) static boolean
tchar
(char c) tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA(package private) static int
token = 1*tchar(package private) static int
token68 = 1*( ALPHA / DIGIT / "-" / "." / "_" / "~" / "+" / "/" ) *"="static void
validateUserAgent
(String userAgent) Validates a user-agent header value.(package private) static boolean
vchar
(char c) VCHAR = %x21-7E
-
Method Details
-
vchar
static boolean vchar(char c) VCHAR = %x21-7E- Parameters:
c
- character- Returns:
- true if c matches VCHAR ABNF rule; else false
- See Also:
-
alpha
static boolean alpha(char c) ALPHA = %x41-5A / %x61-7A- Parameters:
c
- character- Returns:
- true if c matches ALHPA ABNF rule; else false
- See Also:
-
digit
static boolean digit(char c) DIGIT = %x30-39- Parameters:
c
- character- Returns:
- true if c matches DIGIT ABNF rule; else false
- See Also:
-
ctext
static boolean ctext(char c) ctext = HTAB / SP / %x21-27 / %x2A-5B / %x5D-7E / obs-text- Parameters:
c
- character- Returns:
- true if c matches ctext ABNF rule; else false
- See Also:
-
obsText
static boolean obsText(char c) obs-text = %x80-FF- Parameters:
c
- character- Returns:
- true if c matches obs-text ABNF rule; else false
- See Also:
-
comment
comment = "(" *( ctext / quoted-pair / comment ) ")"- Parameters:
s
- input stringpos
- position at start of comment- Returns:
- end position after matching comment ABNF rule; returns pos if token68 was not matched
- See Also:
-
token68
token68 = 1*( ALPHA / DIGIT / "-" / "." / "_" / "~" / "+" / "/" ) *"="- Parameters:
s
- input stringpos
- position at start of token68 character- Returns:
- end position after matching token68 ABNF rule; returns pos if token68 was not matched
- See Also:
-
tchar
static boolean tchar(char c) tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA- Parameters:
c
- character- Returns:
- true if c matches obs-text ABNF rule; else false
- See Also:
-
token
token = 1*tchar- Parameters:
s
- input stringpos
- position at start of token character- Returns:
- end position of a matching token ABNF rule; returns pos if token was not matched
- See Also:
-
bws
BWS = OWSOWS = *( SP / HTAB )
RWS = 1*( SP / HTAB )
- Parameters:
s
- input stringpos
- position at start of token character- Returns:
- end position of a matching BWS ABNF rule
- See Also:
-
sp
1*SP- Parameters:
s
- input stringpos
- position at start of token character- Returns:
- end position of a matching sp ABNF rule
- See Also:
-
product
product = token [ "/" product-version ]product-version = token
- Parameters:
s
- input stringpos
- position at start of product expression- Returns:
- end position of a matching product ABNF rule; pos if not matched
-
qdtext
static boolean qdtext(char c) qdtext = HTAB / SP / "!" / %x23-5B / %x5D-7E / obs-text- Parameters:
c
- character- Returns:
- true if c matches qdtext ABNF rule; else false
- See Also:
-
quotedPair
quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )- Parameters:
s
- input stringpos
- position at start of token character- Returns:
- end position of a matching quoted-pair ABNF rule; pos if the rule was not matched
- See Also:
-
quotedString
quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE- Parameters:
s
- input stringstart
- position at start of token character- Returns:
- end position of a matching BWS ABNF rule
- See Also:
-
isVisibleAscii
Determines whether or not a string is composed entirely of non-whitespace visible ASCII characters, and at least minLength characters, but no longer than 1024.- Parameters:
s
- string to checkminLength
- minimum length- Returns:
- true if all characters are visible ASCII
-
isRootOf
-
createChallenge
Creates an authentication challenge sending to a client via the WWW-Authenticate header.- Parameters:
scheme
- authentication scheme to requestparams
- challenge attributes for informing the client of how to authenticate- Returns:
- authentication challenge
- See Also:
-
parseAuthenticateHeader
public static Iterator<IuWebAuthenticationChallenge> parseAuthenticateHeader(String wwwAuthenticate) Parses challenge parameters from a WWW-Authenticate header.- Parameters:
wwwAuthenticate
- WWW-Authenticate header challenge value- Returns:
- Parsed authentication challenge parameters
-
validateUserAgent
Validates a user-agent header value.User-Agent = product *( RWS ( product / comment ) )
- Parameters:
userAgent
- user-agent header value- See Also:
-
parseQueryString
Parses a query string.- Parameters:
queryString
- query string- Returns:
Map
-
createQueryString
Creates a query string from a map.- Parameters:
params
-Map
of parameter values- Returns:
- query string
-
parseHeader
Parses a header value composed of key/value pairs separated by semicolon ';'.- Parameters:
headerValue
- header value- Returns:
Map
of header elements
-
normalizeHeaderName
Validates and normalizes case for an HTTP header name.Follows each hyphen '-' character with an upper case character; converts other characters
to lower case
- Parameters:
headerName
- HTTP header name- Returns:
String
- Throws:
IllegalArgumentException
- If the name contains non-alphabetic characters other than hyphen '-', or if the name begins or ends with a hyphen.
-
describeStatus
Describes an HTTP status code.- Parameters:
statusCode
- HTTP status code- Returns:
String
-
getInetAddress
Resolves and caches theIP address
for a host name.- Parameters:
hostname
- host name- Returns:
- resolved
InetAddress
-
isInetAddressInRange
Determines whether or not an IP address is included in a CIDR range.- Parameters:
address
- addressrange
- CIDR range- Returns:
- true if the range includes the address; else false
-