niklasb / webkit-server

[not actively maintained] The C++ webkit-server from capybara-webkit with useful extensions and Python bindings
MIT License
48 stars 38 forks source link

webkit_server.Client.headers() parsing error #12

Closed Rolandde closed 9 years ago

Rolandde commented 9 years ago

After visiting google.com, a ValueError is thrown when webkit_server.Client.headers() is called on the Client instance.

Looking at it closer, this is the raw header (newline for clarity): 'Date: Wed, 15 Oct 2014 19:13:52 GMT\nExpires: -1\nCache-Control: private, max-age=0\nContent-Type: text/html; charset=UTF-8\n

Set-Cookie: PREF=ID=b149d0efde2ab49b:FF=0:TM=1413400432:LM=1413400432:S=rbNGJE8Cc7UDPWs_; expires=Fri, 14-Oct-2016 19:13:52 GMT; path=/; domain=.google.com\n

NID=67=PIXzhqbW4y8LyzCR8RnwxIwD-UWlcEon3aNz1Caqklc1yvrpqZZ9LZHrkfXP5XggPAvIlrLUUcRs4n5fVVevSlmaUFS1XrYHlFXnW-PPRXWaStHoxNUCbYfrBVadxcaX; expires=Thu, 16-Apr-2015 19:13:52 GMT; path=/; domain=.google.com; HttpOnly\n

P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."\nContent-Encoding: gzip\nServer: gws\nX-XSS-Protection: 1; mode=block\nX-Frame-Options: SAMEORIGIN\nAlternate-Protocol: 80:quic,p=0.01'

The Set-Cookie header is the culprit. There are two cookies (separated by a newline), but the second cookie does not have a Set-Cookie header. So when Client.headers() splits them by newline, there is no "Set-Cookie:" string (the colon allows it to be split in two) for the second cookie.

I'm not quite sure why the cookies are returned in such a strange format.

niklasb commented 9 years ago

Yes, webkit-server definitely does something wrong here, investigating. Thanks for the report!

niklasb commented 9 years ago

This should be fixed with the newest webkit-server version. The update changes semantics though, the function now returns a list rather than a dictionary (to account for the possibility of having multiple instances of the same header).