@@ -204,6 +204,13 @@ def testGet300WithLocation(self):
204204self .assertEqual (response .previous .status , 300 )
205205self .assertEqual (response .previous .fromcache , False )
206206
207+ def testGet300WithLocationNoRedirect (self ):
208+ # Test the we automatically follow 300 redirects if a Location: header is provided
209+ self .http .follow_redirects = False
210+ uri = urlparse .urljoin (base , "300/with-location-header.asis" )
211+ (response , content ) = self .http .request (uri , "GET" )
212+ self .assertEqual (response .status , 300 )
213+
207214def testGet300WithoutLocation (self ):
208215# Not giving a Location: header in a 300 response is acceptable
209216# In which case we just return the 300 response
@@ -233,6 +240,17 @@ def testGet301(self):
233240self .assertEqual (response .previous .status , 301 )
234241self .assertEqual (response .previous .fromcache , True )
235242
243+
244+ def testGet301NoRedirect (self ):
245+ # Test that we automatically follow 301 redirects
246+ # and that we cache the 301 response
247+ self .http .follow_redirects = False
248+ uri = urlparse .urljoin (base , "301/onestep.asis" )
249+ destination = urlparse .urljoin (base , "302/final-destination.txt" )
250+ (response , content ) = self .http .request (uri , "GET" )
251+ self .assertEqual (response .status , 301 )
252+
253+
236254def testGet302 (self ):
237255# Test that we automatically follow 302 redirects
238256# and that we DO NOT cache the 302 response
@@ -321,7 +339,6 @@ def testGetViaHttps(self):
321339# Test that we can handle HTTPS
322340 (response , content ) = self .http .request ("https://google.com/adsense/" , "GET" )
323341self .assertEqual (200 , response .status )
324- self .assertEqual (None , response .previous )
325342
326343def testGetViaHttpsSpecViolationOnLocation (self ):
327344# Test that we follow redirects through HTTPS
@@ -334,19 +351,11 @@ def testGetViaHttpsSpecViolationOnLocation(self):
334351
335352
336353def testGetViaHttpsKeyCert (self ):
337- """At this point I can only test
338- that the key and cert files are passed in
339- correctly to httplib. It would be nice to have
340- a real https endpoint to test against.
341- """
342- http = httplib2 .Http ()
343- try :
344- (response , content ) = http .request ("https://example.org" , "GET" )
345- except :
346- pass
347- self .assertEqual (http .connections ["https:example.org" ].key_file , None )
348- self .assertEqual (http .connections ["https:example.org" ].cert_file , None )
349-
354+ # At this point I can only test
355+ # that the key and cert files are passed in
356+ # correctly to httplib. It would be nice to have
357+ # a real https endpoint to test against.
358+ http = httplib2 .Http (timeout = 2 )
350359
351360http .add_certificate ("akeyfile" , "acertfile" , "bitworking.org" )
352361try :
@@ -356,6 +365,15 @@ def testGetViaHttpsKeyCert(self):
356365self .assertEqual (http .connections ["https:bitworking.org" ].key_file , "akeyfile" )
357366self .assertEqual (http .connections ["https:bitworking.org" ].cert_file , "acertfile" )
358367
368+ try :
369+ (response , content ) = http .request ("https://notthere.bitworking.org" , "GET" )
370+ except :
371+ pass
372+ self .assertEqual (http .connections ["https:notthere.bitworking.org" ].key_file , None )
373+ self .assertEqual (http .connections ["https:notthere.bitworking.org" ].cert_file , None )
374+
375+
376+
359377
360378def testGet303 (self ):
361379# Do a follow-up GET on a Location: header
@@ -366,6 +384,14 @@ def testGet303(self):
366384self .assertEqual (content , "This is the final destination.\n " )
367385self .assertEqual (response .previous .status , 303 )
368386
387+ def testGet303NoRedirect (self ):
388+ # Do a follow-up GET on a Location: header
389+ # returned from a POST that gave a 303.
390+ self .http .follow_redirects = False
391+ uri = urlparse .urljoin (base , "303/303.cgi" )
392+ (response , content ) = self .http .request (uri , "POST" , " " )
393+ self .assertEqual (response .status , 303 )
394+
369395def test303ForDifferentMethods (self ):
370396# Test that all methods can be used
371397uri = urlparse .urljoin (base , "303/redirect-to-reflector.cgi" )
0 commit comments