N.Venkatesh Naik
N.Venkatesh Naik

Reputation: 134

Not able to read a cookie with ":" in the cookie name in java

I have a cookie with the name having colon in the name of the cookie.

ex: abcd:1=someVAlueOfCookies

I'm not getting this cookie in request.getCookies() of java servlet request.

Can't we have the cookie name with ":" in it.

Please help

Upvotes: 0

Views: 265

Answers (1)

Amadan
Amadan

Reputation: 198334

Cookie JavaDoc:

The name must conform to RFC 2109.

RFC2109:

4.1 Syntax: General

The two state management headers, Set-Cookie and Cookie, have common syntactic properties involving attribute-value pairs. The following grammar uses the notation, and tokens DIGIT (decimal digits) and token (informally, a sequence of non-special, non-white space characters) from the HTTP/1.1 specification [RFC 2068] to describe their syntax.

av-pairs        =       av-pair *(";" av-pair)
av-pair         =       attr ["=" value]        ; optional value
attr            =       token
value           =       word
word            =       token | quoted-string

RFC2068:

token          = 1*<any CHAR except CTLs or tspecials>
tspecials      = "(" | ")" | "<" | ">" | "@"
                     | "," | ";" | ":" | "\" | <">
                     | "/" | "[" | "]" | "?" | "="
                     | "{" | "}" | SP | HT

So, yes, Java's cookie names can't have colons. There are newer cookie specs, where not using colons is a recommendation, not an obligation, but Java seems to conform to this older standard.

Upvotes: 1

Related Questions