toolbelt icon indicating copy to clipboard operation
toolbelt copied to clipboard

BodyPart headers are bytes not str

Open martinxsliu opened this issue 8 years ago • 3 comments

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.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/39912866-bodypart-headers-are-bytes-not-str?utm_campaign=plugin&utm_content=tracker%2F418367&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F418367&utm_medium=issues&utm_source=github).

martinxsliu avatar Dec 06 '16 20:12 martinxsliu

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).

sigmavirus24 avatar Dec 06 '16 20:12 sigmavirus24

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?

martinxsliu avatar Dec 06 '16 23:12 martinxsliu

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.

sigmavirus24 avatar Dec 06 '16 23:12 sigmavirus24