[Python-bugs-list] [ python-Bugs-622042 ] httplib HEAD request fails - keepalive

SourceForge.net noreply@sourceforge.net
Mon, 05 May 2003 09:14:48 -0700


Bugs item #622042, was opened at 2002-10-11 20:15
Message generated for change (Comment added) made by jhylton
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=622042&group_id=5470

Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Mihai Ibanescu (misa)
Assigned to: Jeremy Hylton (jhylton)
Summary: httplib HEAD request fails - keepalive

Initial Comment:
httplib fails to handle HEAD requests correctly when
the server side honors a keep-alive connection.

Per RFC2616, sect. 9.4:

<quot>
The HEAD method is identical to GET except that the
server MUST NOT return a message-body in the response.
The metainformation contained in the HTTP headers in
the response to a HEAD request SHOULD be identical to
the information sent in response to a GET request.
</quot>

This means that HEAD requests are likely to return a
non-zero Content-Length, but with no body.

The attached script, if called against an HTTP/1.1,
keep-alive-aware server (try www.microsoft.com or
www.redhat.com) will hang instead of finishing, because
read() will expect to read some bytes from the connection.

The script was tested against version 1.66 of httplib
(the current HEAD).

HTTP/1.0 and Connection: close (with HTTP/1.1) work as
expected because the server closes the connection.

----------------------------------------------------------------------

>Comment By: Jeremy Hylton (jhylton)
Date: 2003-05-05 16:14

Message:
Logged In: YES 
user_id=31392

Fixed in rev. 1.75 of httplib.py


----------------------------------------------------------------------

Comment By: Mihai Ibanescu (misa)
Date: 2002-10-15 16:03

Message:
Logged In: YES 
user_id=205865

Not necessarily the best approach, but it does fix the problem.
The library already special-case some return codes that
guarantee the body is always zero-length. Signalling that
HEAD requests need the same punishment is all it takes.

----------------------------------------------------------------------

Comment By: Mihai Ibanescu (misa)
Date: 2002-10-15 13:44

Message:
Logged In: YES 
user_id=205865

Yes, I will upload the patch as soon as possible.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-10-14 23:57

Message:
Logged In: YES 
user_id=6380

Sure seems that way. ;-(  For example this hangs:

  python2.3 http-request.py python.org

while this returns correctly:

  python2.3 http-request.py zope.com

Mihai, do you have a proposed fix?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=622042&group_id=5470