Big
. At $BIGCORP jobs, I’ve repeatedly had to write or maintain proxy(ish) code which intercepts HTTP requests and rewrites them in some other form.
To my knowledge, cgi.parse_header is the standard library’s only way to parse an HTTP header like Content-Type in a standard-compliant way. That is, a header that that contains a “main” value (e.g. text/json) in addition to arbitrary key-value pairs.
For example:
>>> from cgi import parse_header
>>> print(parse_header('Content-type: text/html; charset=UTF-8; foo="blick; block=bing"'))
('Content-type: text/html', {'charset': 'UTF-8', 'foo': 'blick; block=bing'})
(@mjpieters points out that email.message.Message contains equivalent functionality, but the interface is not nearly as clean.)
Retaining a straightforward way to invoke the functionality of parse_header and parse_multipart is very important. Seems like http, or a submodule thereof, would be the more natural home for these functions. It’d be good to note them in the PEP.