Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi all,

at the moment I'm working on code which uses CGI::Cookie for fetching and building cookies. So far, so good. I've to admit that I was never interested in the details of cookie headers until today (I've read the RFC now). But now to the problem:

It seems to be absolutly valid that you produce more than one cookie with the same name. Whether this is meaningful or not is something different. But it is possible. It's also possible, that you get more than one cookie with the same name. Looking at the last RFC 6265 shows that the key for a unique cookie is the triple name/domain/path. E.g if you set a cookie 'test' for 'domain.de' and a cookie 'test' for 'host.domain.de' and you're sending a request to host.domain.de you will see two cookies with name 'test' in the Cookie-Header.

CGI::Cookie can't handle this as it uses the cookie name as a key to a hash holding all cookies. So, as soon as you have two cookies with the same name you fetch only the first one. I found this snippet in CGI::Cookie:

# A bug in Netscape can cause several cookies with same name to # appear. The FIRST one in HTTP_COOKIE is the most recent version. $results{$key} ||= $self->new(-name=>$key,-value=>\@values);

Is there any good cookie handling module out there which can handle the case of two or more cookies of same name?

By the way: Plack::Request does also have this "shortcomming". The good thing: tDocumentation states this clearly. It's IMHO a pitty as Plack::Request is relativly new and has Hash::MultiValue introduced in some cases.

I did also some testing of the way browsers handle different cookies (domain, path) with same cookie name. That's really interesting as there is a ugly difference between Firefox/Safari/Chrome and IE/Opera where I do believe at the moment that IE/Opera are doing it right.

Hints appreciated.

Best regards
McA


In reply to Cookie handling by McA

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (8)
    As of 2014-08-01 08:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (257 votes), past polls