NewLionwang / dpkt

Automatically exported from code.google.com/p/dpkt
Other
0 stars 0 forks source link

dpkt.http.Response: server cookies not handled correctly #18

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
data = """HTTP/1.x 200 OK\r\nSet-Cookie: first_cookie=cookie1; path=/;
domain=.example.com\r\nSet-Cookie: second_cookie=cookie2; path=/;
domain=.example.com\r\nContent-Length: 0\r\n\r\n"""
http = dpkt.http.Response(data)
print http

What is the expected output? What do you see instead?
Only the last server cookie "survives" [example script attached]

Original:
----------------------------------------
HTTP/1.x 200 OK
Set-Cookie: first_cookie=cookie1; path=/; domain=.example.com
Set-Cookie: second_cookie=cookie2; path=/; domain=.example.com
Content-Length: 0
----------------------------------------

Parsed:
----------------------------------------
HTTP/1.x 200 OK
set-cookie: second_cookie=cookie2; path=/; domain=.example.com
content-length: 0
----------------------------------------

What version of the product are you using? On what operating system?
dpkt 1.6 (Ubuntu + Windows XP), python 2.5.4

Please provide any additional information below.
The problem is in dpkt.http.parse_headers() - it doesn't take into account
multiple headers with the same name and thus overwrites the value of
"set-cookie" with the value of the last "Set-Cookie" header.

Multiple cookies are very common in real world traffic (i.e. google.com,
facebook.com)
Fixing this bug would really improve this excellent module (thanks dug!) 

Original issue reported on code.google.com by simdr...@gmail.com on 29 Mar 2009 at 10:39

Attachments:

GoogleCodeExporter commented 8 years ago
Fixed in r59.

For example:

            s = """HTTP/1.x 200 OK\r\nSet-Cookie: first_cookie=cookie1; path=/;
domain=.example.com\r\nSet-Cookie: second_cookie=cookie2; path=/;
domain=.example.com\r\nContent-Length: 0\r\n\r\n"""
            r = Response(s)
            print r.headers

will output:

{'set-cookie': ['first_cookie=cookie1; path=/; domain=.example.com',
'second_cookie=cookie2; path=/; domain=.example.com'], 'content-length': '0'}

Headers that appear once will remain a single value, while headers that appear
multiple times will create a list of the present values.

Regards,
Jon Oberheide

Original comment by jon.ober...@gmail.com on 24 Mar 2010 at 3:33