classification
Title: http.client.HTTPMessage.getallmatchingheaders() always returns []
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2, Python 3.1
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gagenellina, mwatkins, orsenthil, petri.lehtinen
Priority: normal Keywords: patch

Created on 2009-01-25 15:24 by mwatkins, last changed 2011-11-23 19:33 by petri.lehtinen.

Files
File name Uploaded Description Edit
http.client.py.patch mwatkins, 2009-01-25 19:29 http.client.py.patch
Messages (6)
msg80509 - (view) Author: Mike Watkins (mwatkins) Date: 2009-01-25 15:24
HTTPMessage.getallmatchingheaders() stopped working sometime after 
Python 3.0 release. In a recent (1 day ago) svn update the 
implementation says the method was copied from rfc822.message; the 
Python 3.x implementation is broken (iterates through self.keys instead 
of header values). I've not looked back to see where the change was 
introduced but I do know that it broke post 3.0 release.

But more importantly than the flaw in this method, the functionality is 
duplicated elsewhere in Python 3.x.

I propose either deprecating getallmatchingheaders() or if it is to be 
kept for compatibility, the fix can be simply replacing the method body 
with:

self.get_all(name)

The docstring for get_all (defined in email.message) affirms that its 
output is indeed compatible with that which was intended for 
getallmatchingheaders().

get_all(self, name, failobj=None) method of client.HTTPMessage instance
    Return a list of all the values for the named field.
    
    These will be sorted in the order they appeared in the original
    message, and may contain duplicates.  Any fields deleted and
    re-inserted are always appended to the header list.
    
    If no such fields exist, failobj is returned (defaults to None).

I've tested the use of get_all against one web server (QP) which runs on 
both Python 2.x and 3.x.

As a result of the broken getallmatchingheaders() the QP web server now 
uses for the same purpose as getallmatchingheaders() instead: 
get_all(name) (defined in email.message.Message in Py3k and 
getheaders(name) (defined in rfc822.Message).

See also issues on documentation and changed API in #4773, #3428
msg80529 - (view) Author: Mike Watkins (mwatkins) Date: 2009-01-25 19:29
Trivial patch for http.client attached.
msg80603 - (view) Author: Gabriel Genellina (gagenellina) Date: 2009-01-27 00:36
I think unified diffs are preferred.
Isn't there an existing test for this method?
msg80606 - (view) Author: Mike Watkins (mwatkins) Date: 2009-01-27 01:53
Re diffs, noted for the future. 
Re tests:

# py3k-devel/Lib/test % grep -r getallmatchingheaders *

... Returns nothing, so not only does the email package need a test for 
this but so does http.client. 

Incidentally test_mailbox.py has a test for the proposed alternative - 
get_all(), which I noted above. That's another good reason for ridding 
the world of getallmatchingheaders() or at least simply calling 
get_all() from within getallmatchingheaders() if compatibility is a 
legitimate concern.
msg80634 - (view) Author: Mike Watkins (mwatkins) Date: 2009-01-27 07:58
Further investigation ( grep -r getallmatchingheaders Lib/* ) reveals 
that in addition to having no tests, and being implemented incorrectly 
in http.client, getallmatchingheaders() is called only once, in 
http.server; that code is also broken (I reported this yesterday in  
#5053).

Maybe Python 3 is where getallmatchingheaders can make a graceful 
goodbye (and a 2to3 conversion added?).
msg148202 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-11-23 19:33
#13425 was marked as duplicate of this issue.
History
Date User Action Args
2011-11-23 19:33:25petri.lehtinensetmessages: + msg148202
2011-11-23 19:31:58petri.lehtinenlinkissue13425 superseder
2011-11-23 19:26:52petri.lehtinensetnosy: + petri.lehtinen
2010-06-26 02:21:35r.david.murraysetnosy: + orsenthil
2010-06-26 00:09:57terry.reedysetversions: + Python 3.2, - Python 3.0
2009-01-27 07:58:01mwatkinssetmessages: + msg80634
2009-01-27 01:53:56mwatkinssetmessages: + msg80606
2009-01-27 00:36:52gagenellinasetnosy: + gagenellina
messages: + msg80603
2009-01-26 13:51:32mwatkinssettitle: http.client.HTTPMessage.getallmatchingheaders() -> http.client.HTTPMessage.getallmatchingheaders() always returns []
2009-01-25 19:29:22mwatkinssetfiles: + http.client.py.patch
keywords: + patch
messages: + msg80529
2009-01-25 15:24:32mwatkinscreate