-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
HTTPHeaderDict in requests #633
Conversation
b57f417
to
838d23a
Compare
Looks like the problem is that >>> h = HTTPHeaderDict({'foo': 'bar'})
>>> h.viewitems()
dict_items([('foo', ('foo', 'bar'))]) /cc people who worked on HTTPHeaerDict @jschneier @ml31415 @seocam |
I had a fix for this in my fork but we closed that PR in favor of @ml31415's header fixes. I don't think I have it lying around anymore either |
@sigmavirus24 Hm are you saying that this was a known bug? I had no idea. :/ Any guidance on how you fixed it? |
The HTTPHeaderDict is implemented to preserve the case. Don't know where this get's messed up. I don't think it's headerdicts fault. |
I think I agree with @shazow: we need to override |
@ml31415 It is headerdict's fault because viewitems returns the wrong thing. In order to support both lowercase and originalcase, we're storing things as So we either need to override viewitems somehow (can't figure out how) or stop inheriting from dict and inherit from MutableMapping as before. ... Erm, what @Lukasa just said while I was writing this. |
Not 100% sure, but I suppose |
@ml31415 It's not us deciding whether to use items or viewitems. It's the Python implementation. :) a = dict(foo='bar')
b = dict(HTTPHeaderDict(a))
a == b # False, because b is {"foo": ("foo", "bar")} |
This is basically what we'd want: https://github.com/kennethreitz/requests/blob/master/requests/structures.py#L14 |
Well, creating a dict that way is just not a lossless operation otherwise. Use |
@ml31415 Again, this is not something I'm doing. It's what would be required to support passing an HTTPHeaderDict into an httplib request and having it Work(tm). |
Not sure if we're understanding each other here, or talk about different things ... :) Any plain dict does not support duplicate header lines. The requests CaseInsensitiveHeaderDict also doesn't do that. I wouldn't expect requests to run with another header implementation without changes. One of them being, to call the necessary conversion function, i.e. The ugly thing about it, iterating the whole headerdict for every http request would be quite a time waster, given that it's a quite rare case to send duplicate headers. As it wasn't implemented so far, no one seems to have missed it too much. |
Y'all are talking past each other. This was an issue I was at least aware of. If we want to fix it, I'll try to get some time during the night this week to fix it |
@sigmavirus24 Still up for taking a crack at this? Would love to get this fixed before the next release. (I think #670 is suffering from this too) |
@shazow , Any idea if this can be fixed quickly or I need to go with a workaround in python-requests, essentially converting back to dict and then to their CaseInsensitiveDict ? |
@atodorov Unfortunately it can only be fixed as quickly as it takes for somebody to fix it. You're welcome to take a crack at it if you have the time to spare, but otherwise I'd put in a workaround. I suggest using |
@shazow - I'm on Python 2.7 so .items is not an option according to your previous comments. I will take additional look at it though. |
@atodorov What's wrong with using |
@sigmavirus24 Any chance you're still up for tackling this soon? I want to do a major version release early next week, would love to get this in. |
Closing in favour of #679. |
Do we want to accept HTTPHeaderDict objects in request header fields interchangeably with dicts/lists of tuples? Any reason why not?
Right now if we do that,
foo=bar
headers get encoded asfoo: ('Foo': 'bar')
Fixes #632