Re: [Httplib2-discuss] Optional non-'redirect following'
Status: Beta
Brought to you by:
jcgregorio
From: Joe G. <jo...@bi...> - 2007-05-03 13:30:34
|
On 4/20/07, Rene Schmit <re...@pt...> wrote: > Joe, > > I am probably completely wrong, but here is how I understand things: > > - redirects are made when the return status is 3xx > - the redirect is made to the URI contained in the 'location' header > > When retrieving a page with httplib2, I get the final page of the chain, > thus: > status = 200 > headers: content-location=<<<new url, as you said>>> > content of final page > > There is NO location field (which is correct for 200, no?). So, the > browser (which is a client of my program) does not get a 3xx, and no > 'location', so does not (and cannot) redirect based on 3xx/location. If > I interpret RFC 2616 (14.14) correctly, the content-location MAY (not > MUST) be used by the client, (uppercase here not used to shout, but > RFC-style:-), and it seems that the three browsers I used to test > (Firefox, Opera and Konqueror) consistently ignore it, and consequently > fetch page content (images etc) from the wrong site. Switching of > redirections solves the problem... Ok, now that makes perfect sense. I have added a 'follow_redirects' attribute to Http() and updated the documentation and unit tests, all available on trunk. > Here is another thing I saw while testing: > when redirecting to another host name, the host header in the request is > not modified. This causes a redirection loop. Example: > > import httplib2 > t='cnn.com' > h=httplib2.Http(cache='/tmp/cache') > h.force_exception_to_status_code = False > r,o=h.request('http://%s/' % t,headers={'Host':t },) Is there a particular reason you are manually setting the Host: header? Httplib2 does that for you automatically by pulling it out of the request URI. In general, I like to allow the user to set any header and have that override the default behavior, following the basic principle that the user knows best, but I'm open to the idea that that principle might break down on redirects. Thanks, -joe -- Joe Gregorio http://bitworking.org |