Salnet007 / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

Content-Location not set after redirect with HEAD requests #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
<http://bitworking.org/projects/httplib2/ref/response-objects.html> states that:

  The Response object also populates the header content-location,
  that contains the URI that was ultimately requested. This is useful
  if redirects were encountered, you can determine the ultimate URI
  that the request was sent to.

However, for HEAD requests this doesn't seem to work:

  >>> from httplib2 import Http
  >>> http = Http()
  >>> resp, body = http.request('http://cmlenz.net/', method='HEAD')
  >>> resp['content-location']
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  KeyError: 'content-location'
  >>> resp.previous
  {'status': '301', 'content-location': 'http://cmlenz.net/', 'location': 'http://www.cmlenz.net/'}

So it looks like the ultimate URL currently needs to be pulled out of the 
'Location' header of the 
'previous' response (if there was one).

Original issue reported on code.google.com by cmlenz on 28 Feb 2008 at 8:12

GoogleCodeExporter commented 9 years ago
This is a problem for me too, but the workaround of using resp.previous seems 
to work for now (thanks!).  

The behavior I see is that 'content-location' is sometimes set and sometimes 
not, but I haven't determined a pattern yet.

Original comment by joshseg...@gmail.com on 4 Jan 2011 at 5:26

GoogleCodeExporter commented 9 years ago
Just a +1 here, I ran into this issue as well.

Original comment by umb...@gmail.com on 30 Mar 2011 at 3:56

GoogleCodeExporter commented 9 years ago
If I'm not mistaken the fix for this should be very simple, in init.py these 
lines:

           elif response.status in [200, 203] and method == "GET":
                # Don't cache 206's since we aren't going to handle byte range requests
                if not response.has_key('content-location'):
                    response['content-location'] = absolute_uri

Just need to change to this:

           elif response.status in [200, 203] and method in ["GET", "HEAD"]:
                # Don't cache 206's since we aren't going to handle byte range requests
                if not response.has_key('content-location'):
                    response['content-location'] = absolute_uri

Original comment by umb...@gmail.com on 30 Mar 2011 at 3:57

GoogleCodeExporter commented 9 years ago

Original comment by joe.gregorio@gmail.com on 13 Jun 2011 at 5:42