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
http.client.HTTPMessage.getallmatchingheaders() always returns [] #57634
Comments
http.client.HTTPMessage.getallmatchingheaders() always returns [] Python 3.2.2: sjankowski@sjankowski:~$ python3
Python 3.2.2rc1 (default, Aug 14 2011, 18:43:44)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.request import urlopen
>>> fp = urlopen('http://www.python.org/')
>>> fp.headers.getallmatchingheaders('Content-Type')
[] At Python 2.7.2 returns the result. sjankowski@sjankowski:~$ python
Python 2.7.2+ (default, Aug 16 2011, 09:23:59)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib import urlopen
>>> fp = urlopen('http://www.python.org/')
>>> fp.headers.getallmatchingheaders('Content-Type')
['Content-Type: text/html\r\n'] |
The problem seems to be in Lib/http/client.py:227. |
Actually the headers are already parsed, so the code should use self.items() instead of self.keys(), check if the key (without ':') matches, and append the key-value pair to the list. |
Please review the attached patch. Like getheaders, getallmatchingheaders would also return (header,value) tuples. It is not backward compatible with 2.7. |
getallmatchinheaders() is not documented, i.e. it's not part of the public API. Furthermore, it's only used by http.server.CGIHTTPRequestHandler, and the comment above it even says that it should be moved there. There are three options now:
In any case, the first thing that should be done is to add a test for CGIHTTPRequestHandler that fails with the current (broken) getallmatchinheaders() implementation. |
This way we won't break any 3.0-3.2 code that is using the function, but the users of such code will start to get DeprecationWarnings in 3.3. There's no meaningful way to fix the function correctly, as the original header data isn't stored anywhere in HTTPMessage or its base class email.message.Message. The function is also obsolete: the get_all() method of email.message.Message can be used. @stachjankowski: How did you find this issue? Are you porting from 2.x to 3.x or have new 3.x code that uses this function? |
|
This strengthens my impression that no-one is actually using the function. Maybe we should just remove it from 3.3. |
Let's make it useful, that's much better instead of removing it. I am |
But there's already a function that does it: HTTPMessage is a subclass of email.message.Message, so it's available in HTTPMessage as well. |
This issue has been reported previously, in bpo-5053. Unfortunately, I overlooked. Sorry. |
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: