From 7053662ed4a1a5c7d867630c44e0657b24b26ae1 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Mon, 8 Jun 2009 01:52:42 -0400 Subject: [PATCH] httplib2-compression section, and some build fiddling --HG-- rename : htmlminimizer.py => util/htmlminimizer.py rename : yuicompressor-2.4.2.jar => util/yuicompressor-2.4.2.jar --- http-web-services.html | 10 +++++++--- publish | 6 +++--- htmlminimizer.py => util/htmlminimizer.py | 0 .../yuicompressor-2.4.2.jar | Bin 4 files changed, 10 insertions(+), 6 deletions(-) rename htmlminimizer.py => util/htmlminimizer.py (100%) rename yuicompressor-2.4.2.jar => util/yuicompressor-2.4.2.jar (100%) 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 $'

How http2lib Handles Compression

-

FIXME +

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'}
+
    +
  1. Every time httplib2 sends a request, it includes an Accept-Encoding header to tell the server that it can handle either deflate or gzip compression. +
  2. In this case, the server has responded with a gzip-compressed payload. By the time the 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. +

How httplib2 Handles Redirects

diff --git a/publish b/publish index 56234a8..29bea23 100755 --- a/publish +++ b/publish @@ -12,9 +12,9 @@ cp -R examples build/ echo "minimizing HTML" -# minimize HTML (XXX this script is quite fragile and relies on knowledge of how I write HTML) +# minimize HTML (NB: this script is quite fragile and relies on knowledge of how I write HTML) for f in *.html; do - python3 htmlminimizer.py "$f" build/"$f" + python3 util/htmlminimizer.py "$f" build/"$f" done # build sitemap @@ -31,7 +31,7 @@ done # minimize JS and CSS echo "minimizing JS" revision=`hg log|grep changeset|cut -d":" -f3|head -1` -java -jar yuicompressor-2.4.2.jar build/j/dip3.js > build/j/dip3-$revision.js +java -jar util/yuicompressor-2.4.2.jar build/j/dip3.js > build/j/dip3-$revision.js # combine jQuery and our script echo "combining JS" diff --git a/htmlminimizer.py b/util/htmlminimizer.py similarity index 100% rename from htmlminimizer.py rename to util/htmlminimizer.py diff --git a/yuicompressor-2.4.2.jar b/util/yuicompressor-2.4.2.jar similarity index 100% rename from yuicompressor-2.4.2.jar rename to util/yuicompressor-2.4.2.jar