CGI::Cookie.parse problem?

Discussion in 'Ruby' started by Bill Kelly, Jan 25, 2006.

  1. Bill Kelly

    Bill Kelly Guest

    Hi,

    I'm interfacing with a site that is sending me back a cookie like
    the following, in the HTTP 'set-cookie' field.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    require 'cgi'

    raw_cookie =
    "ID=867.5309; path=/; domain=site.com, " +
    "SESS_mem=deleted; expires=Mon, 24 Jan 2005 19:48:10 GMT; path=/; domain=.site.com, " +
    "SESS_mem=deleted; expires=Mon, 24 Jan 2005 19:48:10 GMT; path=/; domain=.site.com, " +
    "SESS_mem=xyzzy-plugh-plover; path=/; domain=.site.com"

    k = CGI::Cookie.parse(raw_cookie)

    p k
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    This program outputs:

    {"expires"=>["Mon, 24 Jan 2005 19:48:10 GMT"],
    "domain"=>["site.com, SESS_mem=deleted"],
    "ID"=>["867.5309"], "path"=>["/"]}

    Is this a reasonable way for this set-cookie data to be parsed? It seems
    that CGI::Cookie.parse() isn't aware that there are multiple cookies
    specified in the data... It's sort of giving a mixture of fields from
    the four separate cookies.

    Looking at the RFC, http://www.faqs.org/rfcs/rfc2965.html
    it *seems* to me the above raw_cookie data, conforms to the spec:

    Informally, the Set-Cookie2 response header comprises the token Set-
    Cookie2:, followed by a comma-separated list of one or more cookies.
    Each cookie begins with a NAME=VALUE pair, followed by zero or more
    semi-colon-separated attribute-value pairs.

    Has anyone else run into this? I tried Perl's CGI cookie parsing and
    it returned similarly garbled results for this set-cookie data.

    So I'm wondering if it's really a bug? Or if I'm somehow misusing
    CGI::Cookie.parse() , sending it the wrong format data, or whatever.


    Thanks,

    Regards,

    Bill
     
    Bill Kelly, Jan 25, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. petek
    Replies:
    6
    Views:
    566
    NOBODY
    Jan 24, 2004
  2. Replies:
    19
    Views:
    1,159
    Daniel Vallstrom
    Mar 15, 2005
  3. Xeno Campanoli
    Replies:
    2
    Views:
    160
    Xeno Campanoli
    Jul 10, 2008
  4. Ryan Mulligan

    Is CGI::Cookie::parse terribly broken?

    Ryan Mulligan, Jul 23, 2008, in forum: Ruby
    Replies:
    0
    Views:
    256
    Ryan Mulligan
    Jul 23, 2008
  5. CGI::Cookie problem

    , Apr 12, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    141
Loading...

Share This Page