This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年11月18日 11:03 by stachjankowski, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| 13425.patch | rohini, 2011年11月22日 05:55 | Patch for 13425 | review | |
| Messages (11) | |||
|---|---|---|---|
| msg147849 - (view) | Author: Stanisław Jankowski (stachjankowski) | Date: 2011年11月18日 11:03 | |
http.client.HTTPMessage.getallmatchingheaders() always returns [] Python 3.2.2: Calling the code below does not give the expected result. 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'] |
|||
| msg147850 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2011年11月18日 11:16 | |
The problem seems to be in Lib/http/client.py:227. The code adds a ':' that is not found in the list of headers returned by self.keys(). |
|||
| msg147852 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2011年11月18日 11:36 | |
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. Having a list of key-value pairs seems more useful than having a bare string, but this would be incompatible with 2.7. This function also doesn't seem to be tested and documented, and it's used only once in the stdlib. |
|||
| msg148107 - (view) | Author: rohini (rohini) | Date: 2011年11月22日 05:55 | |
Please review the attached patch. Like getheaders, getallmatchingheaders would also return (header,value) tuples. It is not backward compatible with 2.7. |
|||
| msg148110 - (view) | Author: Petri Lehtinen (petri.lehtinen) * (Python committer) | Date: 2011年11月22日 12:19 | |
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: 1) Document the function to make it officially part of the public API 2) Rename and move the function to http.server 3) Leave it undocumented and just fix it 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. |
|||
| msg148139 - (view) | Author: Petri Lehtinen (petri.lehtinen) * (Python committer) | Date: 2011年11月22日 20:10 | |
4) Deprecate the function to be removed in 3.4 or 3.5 and "fix" it to always return []. 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? |
|||
| msg148173 - (view) | Author: Stanisław Jankowski (stachjankowski) | Date: 2011年11月23日 08:50 | |
> @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? No, it's just random finding. |
|||
| msg148175 - (view) | Author: Petri Lehtinen (petri.lehtinen) * (Python committer) | Date: 2011年11月23日 09:32 | |
> No, it's just random finding. This strengthens my impression that no-one is actually using the function. Maybe we should just remove it from 3.3. |
|||
| msg148177 - (view) | Author: Senthil Kumaran (orsenthil) * (Python committer) | Date: 2011年11月23日 09:44 | |
Let's make it useful, that's much better instead of removing it. I am +1 with Ezio's suggestion on this to return a list of tuples with matching headers. |
|||
| msg148179 - (view) | Author: Petri Lehtinen (petri.lehtinen) * (Python committer) | Date: 2011年11月23日 09:54 | |
> Let's make it useful, that's much better instead of removing it. I am > +1 with Ezio's suggestion on this to return a list of tuples with > matching headers. But there's already a function that does it: http://docs.python.org/dev/library/email.message.html#email.message.Message.get_all HTTPMessage is a subclass of email.message.Message, so it's available in HTTPMessage as well. |
|||
| msg148201 - (view) | Author: Stanisław Jankowski (stachjankowski) | Date: 2011年11月23日 19:10 | |
This issue has been reported previously, in issue5053. Unfortunately, I overlooked. Sorry. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:23 | admin | set | github: 57634 |
| 2011年11月23日 19:32:28 | petri.lehtinen | set | title: http.client.HTTPMessage.getallmatchingheaders() always returns -> http.client.HTTPMessage.getallmatchingheaders() always returns [] |
| 2011年11月23日 19:31:58 | petri.lehtinen | set | superseder: http.client.HTTPMessage.getallmatchingheaders() always returns [] |
| 2011年11月23日 19:10:44 | stachjankowski | set | status: open -> closed resolution: duplicate messages: + msg148201 |
| 2011年11月23日 09:54:27 | petri.lehtinen | set | messages: + msg148179 |
| 2011年11月23日 09:44:13 | orsenthil | set | messages:
+ msg148177 title: http.client.HTTPMessage.getallmatchingheaders() always returns [] -> http.client.HTTPMessage.getallmatchingheaders() always returns |
| 2011年11月23日 09:32:47 | petri.lehtinen | set | messages: + msg148175 |
| 2011年11月23日 08:50:33 | stachjankowski | set | messages: + msg148173 |
| 2011年11月22日 20:10:36 | petri.lehtinen | set | messages: + msg148139 |
| 2011年11月22日 12:19:27 | petri.lehtinen | set | messages: + msg148110 |
| 2011年11月22日 09:57:51 | orsenthil | set | nosy:
+ orsenthil |
| 2011年11月22日 05:55:03 | rohini | set | files:
+ 13425.patch nosy: + rohini messages: + msg148107 keywords: + patch |
| 2011年11月18日 11:36:11 | ezio.melotti | set | keywords:
+ easy stage: test needed messages: + msg147852 versions: + Python 3.3 |
| 2011年11月18日 11:25:49 | petri.lehtinen | set | nosy:
+ petri.lehtinen |
| 2011年11月18日 11:16:53 | ezio.melotti | set | nosy:
+ ezio.melotti messages: + msg147850 |
| 2011年11月18日 11:03:49 | stachjankowski | create | |