Package com.google.appengine.tools.util
Class HttpHeaderParser
java.lang.Object
com.google.appengine.tools.util.HttpHeaderParser
A collection of routines for parsing HTTP headers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoideatChar(char ch) Eat a given character.voideatLWS()Eat linear white space (zero or more characters).Eat a quoted string.eatToken()Eat a token.Eat a token or a quoted string.Eat a Netscape V0 cookie date.Eat a Netscape V0 cookie token.Eat a Netscape V0 cookie value.static StringgetContentCharset(String contentType) Get a charset from content type.booleanisEnd()Are we at the end of the header?static StringBuffermakeAttributeValuePair(String attribute, String value) HTTP-encode an attribute=value pair.intpeek()Get next character without removing it.
-
Constructor Details
-
HttpHeaderParser
Create a parser.- Parameters:
header- header string, never null.
-
-
Method Details
-
isEnd
public boolean isEnd()Are we at the end of the header?- Returns:
- true if the header ended, false if one or more characters remain.
-
peek
public int peek()Get next character without removing it.- Returns:
- next character, or -1 if end of input.
-
eatChar
Eat a given character.- Parameters:
ch- character to expect.- Throws:
HttpHeaderParseException- if input does not start with ch.
-
eatLWS
public void eatLWS()Eat linear white space (zero or more characters). -
eatToken
Eat a token.- Returns:
- token text, at least one character.
- Throws:
HttpHeaderParseException- if input does not start with a token.
-
eatQuotedString
Eat a quoted string.- Returns:
- value read, can be empty.
- Throws:
HttpHeaderParseException- if input does not start with a qstring.
-
eatTokenOrQuotedString
Eat a token or a quoted string.- Returns:
- value read, can be empty.
- Throws:
HttpHeaderParseException- if input does not start with either.
-
eatV0CookieToken
Eat a Netscape V0 cookie token.- Returns:
- a token, of length at least one.
- Throws:
HttpHeaderParseException- if input does not start with a V0 tok.
-
eatV0CookieValue
Eat a Netscape V0 cookie value.- Returns:
- a value, can be empty.
-
eatV0CookieDate
Eat a Netscape V0 cookie date.- Returns:
- date, never null.
- Throws:
HttpHeaderParseException- if input does not start with a date.
-
makeAttributeValuePair
HTTP-encode an attribute=value pair.- Parameters:
attribute- the attribute, must be an HTTP token.value- attribute value, must not contain CR or LF.- Returns:
- properly encoded attribute=value pair.
- Throws:
IllegalArgumentException- if either argument is illegal.
-
getContentCharset
Get a charset from content type.- Parameters:
contentType- Content-Type header value.- Returns:
- charset, or null if not present.
- Throws:
HttpHeaderParseException- if contentType is misformatted.
-