diff --git a/http-web-services.html b/http-web-services.html index 2b36c1b..107ddb6 100644 --- a/http-web-services.html +++ b/http-web-services.html @@ -494,18 +494,18 @@ user-agent: Python-httplib2/$Rev: 259 $'
http2lib Handles CompressionFIXME +
HTTP supports two types of compression. httplib2 supports both of them.
>>> response, content = h.request('http://diveintopython3.org/')
connect: (diveintopython3.org, 80)
send: b'GET / HTTP/1.1
Host: diveintopython3.org
-accept-encoding: deflate, gzip
+accept-encoding: deflate, gzip ①
user-agent: Python-httplib2/$Rev: 259 $'
reply: 'HTTP/1.1 200 OK'
>>> print(dict(response.items()))
-{'-content-encoding': 'gzip',
+{'-content-encoding': 'gzip', ②
'accept-ranges': 'bytes',
'connection': 'close',
'content-length': '6657',
@@ -517,6 +517,10 @@ reply: 'HTTP/1.1 200 OK'
'server': 'Apache',
'status': '304',
'vary': 'Accept-Encoding,User-Agent'}
+httplib2 sends a request, it includes an Accept-Encoding header to tell the server that it can handle either deflate or gzip compression.
+request() method returns, httplib2 has already decompressed the body of the response and placed it in the content variable. If you’re curious about whether or not the response was compressed, you can check the response dictionary; otherwise, don’t worry about it.
+httplib2 Handles Redirects