Problem with httplib and HEAD request

Discussion in 'Python' started by Mitch.Garnaat@gmail.com, Mar 28, 2006.

  1. Guest

    Hi -

    I'm writing some Python code to interact with Amazon's S3 service. One
    feature of S3 is that it will allow you to use the HTTP HEAD request to
    retrieve metadata about an S3 object without actually retrieving the
    content of the object. In trying to use this feature, I'm running into
    what I think is a bug in httplib.py.

    If the resource I perform the HEAD request on exists within S3 then
    everything is fine. If, however, the resource doesn't exist then a 404
    is returned. If the request had been a GET rather than a HEAD the body
    of the response would be some XML that gave further information about
    the error status returned. However, for a HEAD request no body can be
    returned so the body is empty. The error response, for either HEAD or
    GET, does include the following header:

    transfer-encoding: chunked

    And this seems to be causing confusion in httplib.py. I have to call
    the read method of the response or else I get a ResponseNotReady
    exception on my next request. When I attempt to read the body of the
    error response to the HEAD request it is passed onto the _read_chunked
    method where it immediately tries to do a readline() on the connection
    which, of course, hangs because no body has been sent in the response.

    So, I know this is kind of a boundary condition and perhaps it hasn't
    come up before but it seems that the behavior of httplib is incorrect.
    I think something needs to be added to the _read_chunked method which
    checks if the request is a GET and, if so, just reads zero bytes from
    the socket and returns.

    Any comments? Thanks,

    Mitch
    , Mar 28, 2006
    #1
    1. Advertising

  2. Guest

    For what it's worth, I made the following change to httplib.py and it
    seems to have solved my problems:

    c455
    < if self.chunked:
    ---
    > if self.chunked and self._method != 'HEAD':


    I'm using Python 2.4.1 on MacOS.

    Mitch
    , Mar 29, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian W
    Replies:
    10
    Views:
    751
    Brian W
    Jul 2, 2003
  2. showme

    PHP and ASP.NET go HEAD to HEAD

    showme, Jul 8, 2004, in forum: ASP .Net
    Replies:
    13
    Views:
    709
    Sherif ElMetainy
    Jul 10, 2004
  3. Karl
    Replies:
    0
    Views:
    383
  4. deelan
    Replies:
    0
    Views:
    1,235
    deelan
    Apr 1, 2004
  5. Jiho Han

    Write into <HEAD></HEAD> section?

    Jiho Han, Jan 14, 2004, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    218
    Sam Fields
    Jan 16, 2004
Loading...

Share This Page