public class CookieParser extends Parser implements Iterable<Cookie>
cookie = "Cookie:" cookie-version 1*((";" | ",") cookie-value) cookie-value = NAME "=" VALUE [";" path] [";" domain] cookie-version = "$Version" "=" value NAME = attr VALUE = value path = "$Path" "=" value domain = "$Domain" "=" valueThe cookie header may consist of several cookies. Each cookie can be extracted from the header by examining the it syntax of the cookie header. The syntax of the cookie header is defined in RFC 2109.
Each cookie has a $Version
attribute followed by multiple
cookies. Each contains a name and a value, followed by an optional
$Path
and $Domain
attribute. This will parse
a given cookie header and return each cookie extracted as a
Cookie
object.
Constructor and Description |
---|
CookieParser()
Create a
CookieParser that contains no cookies. |
CookieParser(String header)
This is primarily a convineance constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
init()
Resets the cookie and the buffer variables for this
CookieParser . |
Iterator<Cookie> |
iterator()
This is used to acquire the cookie values from the provided
the provided source text.
|
protected void |
parse()
This will extract the next
Cookie from the
buffer. |
void |
reset()
This is used so that the collection of
Cookies
can be reiterated. |
protected boolean |
skip(String text)
This is used to skip an arbitrary
String within the
char buf. |
digit, ensureCapacity, parse, space, toLower
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public CookieParser()
CookieParser
that contains no cookies.
the instance will return false
for the
hasNext
method. cookies may be parsed using
this instance by using the parse
method.public CookieParser(String header)
String
given to extract the cookies. This could be
achived by calling the default no-arg constructor and then using
the instance to invoke the parse
method on that
String
.header
- a String
containing a cookie valueprotected void init()
CookieParser
. It is used to set the
state of the parser to start parsing a new cookie.protected void parse()
Cookie
from the
buffer. If all the characters in the buffer have already
been examined then this method will simply do nothing.
Otherwise this will parse the remainder of the buffer
and (if it follows RFC 2109) produce a Cookie
.protected boolean skip(String text)
String
within the
char
buf. It checks the length of the String
first to ensure that it will not go out of bounds. A comparison
is then made with the buffers contents and the String
if the reigon in the buffer matched the String
then the
offset within the buffer is increased by the String
's
length so that it has effectively skipped it.
This skip
method will ignore all of the whitespace text.
This will also skip trailing spaces within the the input text and
all spaces within the source text. For example if the input was
the string "s omete xt" and the source was "some text to skip" then
the result of a skip ignoring spaces would be "to skip" in the
source string, as the trailing spaces are also eaten by this.
public Iterator<Cookie> iterator()
public void reset()
Cookies
can be reiterated. This allows the collection to be reused.
The reset
method will invoke the super classes
init
method. This will reinitialize this
Parser
so the cookie will be reparsed.Copyright © 2021. All rights reserved.