I wish to "retrieve" the cookies sent by the client in my subclass of BaseHTTPRequestHandler
.
Firstly I'm unsure of the exact sequence of sending of headers, in a typical HTTP request and response this is my understanding of the sequence of events:
- Client sends request (method, path, HTTP version, host, and ALL headers).
- The server responds with a response code, followed by a bunch of headers of its own.
- The server then sends the body of the response.
When exactly is the client's POST data sent? Does any overlapping occur in this sequence as described above?
Second, when is it safe to assume that the "Cookie" header has been received by the server. Should all of the client headers have been received by the time self.send_response
is called by the server? When in the HTTP communication is the appropriate time to peek at cookie headers in self.headers
?
Thirdly, what is the canonical way to parse cookies in Python. I currently believe a Cookie.SimpleCookie
should be instantiated, and then data from the cookie headers some how fed into it. Further clouding this problem, is the Cookie classes clunkiness when dealing with the HTTPRequestHandler interfaces. Why does the output from Cookie.output()
not end with a line terminator to fit into self.wfile.write(cookie.output())
, or instead drop the implicitly provided header name to fit nicely into self.send_header("Set-Cookie", cookie.output())
Finally, the cookie classes in the Cookie
module, give the illusion that they're dictionaries of dictionaries. Assigning to different keys in the cookie, does not pack more data into the cookie, but rather generates more cookies... all apparently in the one class, and each generating its own Set-Cookie header. What is the best practise for packing containers of values into cookie(s)?