[Zope-Checkins] CVS: Zope/lib/python/ZPublisher - HTTPResponse.py:1.64
Brian Lloyd
brian@zope.com
Thu, 20 Jun 2002 11:17:08 -0400
Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv4952
Modified Files:
HTTPResponse.py
Log Message:
Merged Brad Clements compression refinements.
=== Zope/lib/python/ZPublisher/HTTPResponse.py 1.63 => 1.64 ===
_error_format='text/html'
_locked_status = 0
- use_HTTP_content_compression = 0 # indicate if setBody should content-compress output
+
+ # Indicate if setBody should content-compress output.
+ # 0 - no compression
+ # 1 - compress if accept-encoding ok
+ # 2 - ignore accept-encoding (i.e. force)
+ use_HTTP_content_compression = 0
def __init__(self,body='',status=200,headers=None,
stdout=sys.stdout, stderr=sys.stderr,):
@@ -331,7 +336,14 @@
self.body = z
self.setHeader('content-length', newlen)
self.setHeader('content-encoding','gzip')
-
+ if self.use_HTTP_content_compression == 1:
+ # use_HTTP_content_compression == 1 if force was
+ # NOT used in enableHTTPCompression().
+ # If we forced it, then Accept-Encoding
+ # was ignored anyway, so cache should not
+ # vary on it. Otherwise if not forced, cache should
+ # respect Accept-Encoding client header
+ self.appendHeader('Vary','Accept-Encoding')
return self
def enableHTTPCompression(self,REQUEST={},force=0,disable=0,query=0):
@@ -342,7 +354,8 @@
disable -- set true to disable compression
query -- just return if compression has been previously requested
- returns -- 1 if compression will be performed, 0 otherwise
+ returns -- 1 if compression will be attempted, 2 if compression
+ is forced, 0 if no compression
The HTTP specification allows for transfer encoding and content
encoding. Unfortunately many web browsers still do not support
@@ -377,9 +390,10 @@
self.use_HTTP_content_compression = 0
elif force or (REQUEST.get('HTTP_ACCEPT_ENCODING','').find('gzip') != -1):
- self.use_HTTP_content_compression = 1
- if not force:
- self.appendHeader('Vary', 'Accept-Encoding')
+ if force:
+ self.use_HTTP_content_compression = 2
+ else:
+ self.use_HTTP_content_compression = 1
return self.use_HTTP_content_compression