--- urllib2.py 2006-06-19 11:22:56.000000000 +0200 +++ urllib2.py.new 2006-06-19 11:22:27.000000000 +0200 @@ -982,6 +982,9 @@ headers = dict(req.headers) headers.update(req.unredirected_hdrs) + hasAcceptEncoding = "Accept-Encoding" in headers + if not hasAcceptEncoding: headers["Accept-Encoding"] = "gzip" + # We want to make an HTTP/1.1 request, but the addinfourl # class isn't prepared to deal with a persistent connection. # It will try to read all remaining data from the socket, @@ -1006,8 +1009,12 @@ # XXX It might be better to extract the read buffering code # out of socket._fileobject() and into a base class. - r.recv = r.read - fp = socket._fileobject(r) + if not hasAcceptEncoding and r.getheader("Content-Encoding") == 'gzip': + import gzip + fp = gzip.GzipFile(fileobj=r,mode='rb') + else: + r.recv = r.read + fp = socket._fileobject(r) resp = addinfourl(fp, r.msg, req.get_full_url()) resp.code = r.status