diff --git a/http-web-services.html b/http-web-services.html index b9db5ea..f16dabe 100644 --- a/http-web-services.html +++ b/http-web-services.html @@ -300,7 +300,7 @@ Content-Type: application/xml >>> data2 == data True
    -
  1. The server is still sending the same array of “smart” headers: Cache-Control and Expires to allow caching, Last-Modified and ETag to enable “not-modified” tracking. Even the Vary: Accept-Encoding header hints that the server would support compression, if only you would bloody well ask for it. But you’re not listening. +
  2. The server is still sending the same array of “smart” headers: Cache-Control and Expires to allow caching, Last-Modified and ETag to enable “not-modified” tracking. Even the Vary: Accept-Encoding header hints that the server would support compression, if only you would ask for it. But you didn’t.
  3. Once again, fetching this data downloads the whole 3070 bytes…
  4. …the exact same 3070 bytes you downloaded last time.
@@ -311,21 +311,101 @@ Content-Type: application/xml

Introducing httplib2

-

FIXME +

To use httplib2, create an instance of the httplib2.Http class. -

How httplib2 handles caching

+
+>>> import httplib2
+>>> h = httplib2.Http('.cache')
+>>> response, content = h.request('http://diveintopython3.org/examples/feed.xml')
+>>> response.status
+200
+>>> content[:52]
+b'<?xml version="1.0" encoding="utf-8"?>\r\n<feed xmlns='
+>>> len(content)
+3070
+
    +
  1. FIXME +
+ +

How httplib2 Handles Caching

FIXME -

How httplib2 handles Last-Modified and ETag headers

+
+# continued from previous example
+>>> response2, content2 = h.request('http://diveintopython3.org/examples/feed.xml')
+>>> response2.status
+200
+>>> content2[:52]
+b'<?xml version="1.0" encoding="utf-8"?>\r\n<feed xmlns='
+>>> len(content2)
+3070
+
    +
  1. FIXME +
+ +
+# NOT continued from previous example!
+# Please exit out of the interactive shell
+# and launch a new one.
+>>> import httplib2
+>>> httplib2.debuglevel = 1
+>>> h = httplib2.Http('.cache')
+>>> response, content = h.request('http://diveintopython3.org/examples/feed.xml')
+>>> len(content)
+3070
+>>> response.status
+200
+>>> response.fromcache
+True
+
    +
  1. FIXME +
+ +
+# continued from previous example
+>>> response2, content2 = h.request('http://diveintopython3.org/examples/feed.xml',
+...     headers={'cache-control':'no-cache'})
+connect: (diveintopython3.org, 80)
+send: b'GET /examples/feed.xml HTTP/1.1
+Host: diveintopython3.org
+user-agent: Python-httplib2/$Rev: 259 $
+accept-encoding: deflate, gzip
+cache-control: no-cache'
+reply: 'HTTP/1.1 200 OK'
+…further debugging information omitted…
+>>> response2.status
+200
+>>> response2.fromcache
+False
+>>> print(dict(response2.items()))
+{'status': '200',
+ 'content-length': '3070',
+ 'content-location': 'http://diveintopython3.org/examples/feed.xml',
+ 'accept-ranges': 'bytes',
+ 'expires': 'Wed, 03 Jun 2009 00:40:26 GMT',
+ 'vary': 'Accept-Encoding',
+ 'server': 'Apache',
+ 'last-modified': 'Sun, 31 May 2009 22:51:11 GMT',
+ 'connection': 'close',
+ '-content-encoding': 'gzip',
+ 'etag': '"bfe-255ef5c0"',
+ 'cache-control': 'max-age=86400',
+ 'date': 'Tue, 02 Jun 2009 00:40:26 GMT',
+ 'content-type': 'application/xml'}
+
    +
  1. FIXME +
+ +

How httplib2 Handles Last-Modified and ETag headers

FIXME -

How http2lib handles compression

+

How http2lib Handles compression

FIXME -

How httplib2 handles redirects

+

How httplib2 Handles redirects

FIXME