New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't modify type of headers object within HTTPConnection.request() #2021
Comments
Where do we then normalize things and what if someone adds a value that's bytes and another that's a str? Edit to add an example: headers = HTTPHeaderDict()
headers.add("Cookie", "sessionId=abc1234")
headers.add("Cookie", b"lang=en-US") I don't think headers = HTTPHeaderDict()
headers.add("Content-Length", b"7")
headers.add("Content-Length", "8") We shouldn't be emitting |
I've been mulling over this more than I probably should. I, for one, would rather see us pick a "right" way to pass data to urllib3. In other words, I'd rather see us standardize (somehow) on bytes. I find that trying to use text can be a bit too tricky in something like this especially if we take the stance of An alternative, if we want to provide everything, which I'm less fond of us taking a tact like the standard library. |
Just putting some thoughts down, here's the state of things:
Given this information the change that allows skipping user-agent would need to be tweaked to account for this and pass headers as the same type as input to For v2: I'm not sure how much value versus we get by changing much of what Regarding the other points raised:
|
We're going to likely store a dict under the covers regardless, can we not simply do a translation?
Then what does
Huh? Why?
Depends on how you receive it? If we're keeping dictionaries then I'd argue
So then we're introducing a special case where we don't raise We can classify headers (more or less):
It shouldn't be hard to have a I think that over the years, a big problem people run into (not just using requests/urllib3 but in many languages) is duplicating headers they shouldn't be able to. In |
Just an FYI I'm going to respond out-of-order from your reply.
Currently it raises a
I was confusing
So with v2 we can work a lot more on request headers. Currently |
One last thought, because some headers can be repeated, I'm genuinely of the opinion that dictionaries are the wrong way to think about headers. They really are a sequence of names and values. Accessing them like a dictionary is convenient, but part of me wishes we could standardize on a list of tuples (which would be hard for deduplication, etc.) |
Captured from these two comments:
Follow this logic:
b", ".join(val[1:])
", ".join(val[1:])
This way if a user uses mixed types they still get the same explosion? I'd like a little poking around with what happens when httplib is passed both bytes and str headers on Python 2.x since it had strange behavior when doing so with HTTP method and URL.
cc @jalopezsilva
The text was updated successfully, but these errors were encountered: