toolbelt
toolbelt copied to clipboard
BodyPart headers are bytes not str
The BodyPart.headers
dictionary returned by the MultipartDecoder
uses bytes for keys and values, while the requests.Response
object uses string keys and values. Is there a reason that the headers should be bytes? Otherwise, I propose that we make the two consistent, then we can use the same logic to process normal and multipart responses.
I'll be happy to submit a PR for this, it looks like a small change.
The headers are not actually fully decoded which is exactly why they're bytes. We don't do any post processing (i.e., what would be required to handle RFC 2231 headers).
I'm not particularly familiar with the state of world regarding non-ascii headers.
I do see that we are decoding the headers here using the encoding provided to MultipartDecoder. Is the reasoning for that to simply pass it through to the header parser without regard to the underlying meaning of the string?
Is the reasoning for that to simply pass it through to the header parser without regard to the underlying meaning of the string?
Headers have a specific format. Header values have specific semantic meaning. Parsing the header format to make them easier to use doesn't really equate to us needing to decode headers. There's no equivalence there.