Random ...
 
December 2017
S M T W T F S
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Tags ...
Links



python+zope++:: mod_deflate, zope, apache and squid; or how to deliver compressed contents
Posted at 06.May,2005 17:21  Comments 1 / Trackbacks 0 / Like this post!
Technorati tag(s):
Most modern browsers nowadays accept gzip encoding. Apache 1.x has mod_gzip. Apache 2 has mod_deflate.

mod_gzip was done by third part while mod_deflate comes from the apache httpd group (methinks).

Here's what I did to deliver compressed contents to browsers who'd accept them.

Nothing to be done on zope. Zope just need to churn out the contents. Nothing needed on squid too.

On apache, add the following in httpd.conf. These are actually from the manual with some tweaks.

Check the comments for what some of the directives do.


#enable deflate on select contents
#AddOutputFilterByType DEFLATE text/html text/plain text/xml
#or enable on all
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
#this to make sure squid cache accordingly. but
#will it? we'll see in a couple of days
Header append Vary User-Agent env=!dont-vary
#compression level (1-9)
DeflateCompressionLevel 3
#logging
#DeflateFilterNote ratio

#LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate
#CustomLog logs/deflate_log deflate
#or accurate logging
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio

LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%) "%{User-agent}i"' deflate
CustomLog logs/deflate_log deflate



Here's the deflate_log. Some contents are compressed while others are not. Good? Probably.


"GET /location/some.css HTTP/1.0" 1325/8775 (15%)
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
"GET / HTTP/1.0" 4442/18294 (24%) "Mozilla/4.0 (compatible; MSIE
5.01; Windows 98)"
"GET /location/some.gif
HTTP/1.0" -/- (-%) "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
"GET /location/someother.gif
HTTP/1.0" -/- (-%) "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
"GET /location/some.js HTTP/1.0" -/- (-%) "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.0)"
"GET /location/someother.css HTTP/1.0" 964/4824 (19%)
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
"GET /location/other.gif
HTTP/1.0" -/- (-%) "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
"GET /location/someother.css HTTP/1.0" 964/4824 (19%)
"Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)"
"GET /location/somecontent
HTTP/1.0" 3078/8568 (35%) "Mozilla/5.0 (compatible; Yahoo! Slurp;
http://help.yahoo.com/help/us/ysearch/slurp)"


If we look closely, the same contents are requested again by squid for different agents. So, the directive to check for user agents does work since squid never cache the same contents for different agents.

We can only confirm after a few days test. If no users complained then things should be good.

I've had bad luck delivering compressed contents in my previous lifetime using mod_gzip and apache 1.x. Probably because things are cached regardless of the user agents.

Wish me luck!

Bookmark and Share

Is this entry helpful? Comments/Donate/Click some google ads.  
Trackback is http://myzope.kedai.com.my/blogs/kedai/26/tbping 

Comments
Re: mod_deflate, zope, apache and squid

Thanks

anthony  at 09.May,2005 21:18
Post a comment