-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
http.client.HTTPMessage.getallmatchingheaders() always returns [] #49303
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
Comments
HTTPMessage.getallmatchingheaders() stopped working sometime after But more importantly than the flaw in this method, the functionality is I propose either deprecating getallmatchingheaders() or if it is to be self.get_all(name) The docstring for get_all (defined in email.message) affirms that its get_all(self, name, failobj=None) method of client.HTTPMessage instance
I've tested the use of get_all against one web server (QP) which runs on As a result of the broken getallmatchingheaders() the QP web server now See also issues on documentation and changed API in bpo-4773, bpo-3428 |
Trivial patch for http.client attached. |
I think unified diffs are preferred. |
Re diffs, noted for the future. # py3k-devel/Lib/test % grep -r getallmatchingheaders * ... Returns nothing, so not only does the email package need a test for Incidentally test_mailbox.py has a test for the proposed alternative - |
Further investigation ( grep -r getallmatchingheaders Lib/* ) reveals Maybe Python 3 is where getallmatchingheaders can make a graceful |
bpo-13425 was marked as duplicate of this issue. |
So, how to move this further? In bpo-13425 Petri proposes 4 alternatives, copying them here:
I assume 4) meant: My proposal is a more explicitly spelled out version 2): The rationale for removal without deprecation is:
Mike can you tell us how you found out about this breakage? Were you using the function? Did you use something else to workaround it since it's broken now? Senthil, Petri do you agree with option 5)? If so I can provide a patch. |
My 4) actually meant that it should always return []. This is what it currently does, so it could be spelled out clearly in the code. IIRC, getallmatchingheaders() cannot be emulated one-to-one using get_all(), because it handles continuation lines differently. That's why I thought removing or deprecating without fixing it would be the best. rfc822.Message.getallmatchingheaders() is documented in Python 2, so removing it could make it harder to port code from Python 2 to Python 3. On the other hand, it's broken, so having it removed could actually make things better by not introducing hard-to-find bugs. All in all, I'm not sure what's the best thing to do. |
The CGIHTTPRequestHandler fix and test would be the best thing to start with, though, as it's not related to the eventual fate of getallmatchingheaders(). |
I agree with Catalin’s proposal to remove it straight away. It just causes confusion, and to me the intended behaviour is not equivalent to Message.get_all(). I would remove the entire HTTPMessage class and replace it as an alias of email.message.Message. |
Posting a patch to remove the entire HTTPMessage class. This assumes my patch for bpo-5054 is accepted, which will remove the only existing reference to getallmatchingheaders(). |
It is certainly true that getallmatchingheaders is broken... because the data it is looking at has changed format. Here is a replacement that is as compatible as can be, based on the changed format. name = name.lower()
n = len(name)
lst = []
for line, data in self.items():
if line.lower() == name:
lst.append(line + ': ' + data)
return lst The changed format has merged continuation lines, and separated keys and values into a list of duplet tuples. Iterators keys, values, and items exist, keys are not necessarily unique. |
@vadmium, do you mind to create a PR based on your patch? It needs a NEWS and What's New entries, and perhaps some updates in the stdlib documentation. |
Sorry Serhiy I’m not likely to create a pull request. I still think removing the class is the way forward, and I don’t mind if someone else makes a pull request though. |
Note that |
cc @hugovk Maybe we can use this issue to schedule the deprecation and removal of this function? |
I think it'll be clearer to open a new one and close this. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: