diff --git a/http-web-services.html b/http-web-services.html index c9e1baf..3b8b2b5 100755 --- a/http-web-services.html +++ b/http-web-services.html @@ -578,7 +578,7 @@ reply: 'HTTP/1.1 200 OK'
# continued from the previous example ->>> print(dict(response.items())) ① +>>> response ① {'status': '200', 'content-length': '3070', 'content-location': 'http://diveintopython3.org/examples/feed.xml', ② @@ -597,7 +597,35 @@ reply: 'HTTP/1.1 200 OK'
request() method is the response from the final URL.
httplib2 adds the final URL to the response dictionary, as content-location. This is not a header that came from the server; it’s specific to httplib2.
The response you get back gives you information about the final URL. What if you want more information about the intermediate URLs, the ones that eventually redirected to the final URL? httplib2 lets you do that, too.
+
+
+# continued from the previous example +>>> response.previous ① +{'status': '302', + 'content-length': '228', + 'content-location': + 'http://diveintopython3.org/examples/feed-302.xml', + 'expires': 'Thu, 16 Jul 2009 20:15:58 GMT', + 'server': 'Apache', + 'connection': 'close', + 'location': 'http://diveintopython3.org/examples/feed.xml', + 'cache-control': 'max-age=86400', + 'date': 'Wed, 15 Jul 2009 20:15:58 GMT', + 'content-type': 'text/html; charset=iso-8859-1'} +>>> type(response) ② +<class 'httplib2.Response'> +>>> type(response.previous) +<class 'httplib2.Response'> +>>> response.previous.previous ② +>>>+
httplib2 followed to get to the current response object.
+httplib2.Response objects.
+None.
What happens if you request the same URL again?