energyd / httplib2

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

Handling of Http.force_exception_to_status_code is wrong #213

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Set Http.force_exception_to_status_code to True
2. set redirections=0 parameter when calling Http object request method
3.

What is the expected output? What do you see instead?

The use case is trying to get cookie returned by Central Authentication Server 
(CAS) in redirect 
response. To do this I have to disable httplib2 following redirects so I can 
look at the headers in
the redirect (302) response. But instead of returning a response with status of 
302 it returns a response
of status = 500.  

This is counter intuitive. In the event of a max redirects exceeded it 
shouldn't come back as a server error.
It should just return the redirect.

One way to fix this is to change to code so it reads

if self.force_exception_to_status_code:
                if isinstance(e, HttpLib2ErrorWithResponse):
                    response = e.response
                    content = e.content
                    response.status = e.response.status
                    response.reason = e.response.reason

Another way would be to make the change specific to the redirection is
 if isinstance(e, RedirectLimit):
                    response = e.response
                    content = e.content
                    response.status = e.response.status
                    response.reason = e.response.reason
elif isinstance(e, HttpLib2ErrorWithResponse):
                    response = e.response
                    content = e.content
                    response.status = 500
                    response.reason = str(e)

What version of the product are you using? On what operating system?
__version__ = "0.7.4"

Please provide any additional information below.

Original issue reported on code.google.com by smithsam...@gmail.com on 27 Jun 2012 at 10:57