[Twisted-web] cookie parsing

Wensheng Wang wenshengwang at gmail.com
Wed Jul 20 07:40:17 MDT 2005

Today I had a problem of not getting back cookie data in twisted web.
After browsing the code I found the culprit.  My cookie value has '='
in it.
In twisted.web.http.py, the code of  parsing of a cookie:
        cookietxt = self.getHeader("cookie")
        if cookietxt:
            for cook in cookietxt.split(';'):
                cook = cook.lstrip()
                    k, v = cook.split('=')
                    self.received_cookies[k] = v
                except ValueError:

because I have '=' in the value, that k,v=cook.split('=') caused error
and that "pass" hide the error.
Because I used modpython and cgi for the same cookie, the there was no
problem, I assume equal sign in cookie value is legal.

May I suggest change the parsing code to:
or something like this.

More information about the Twisted-web mailing list