betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

28 March 2006

How-To For Conditional HTTP GET For COREBlog

Patch for handling the If-Modified-Since header
 

Last nights hack seems to work just fine. Nobody has complained yet and the log shows some successfull entries. As seen in the previous post, conditional HTTP GET is saving bandwidth by giving the browser (or RSS reader) the page content only when it has changed since a given date. So, time to publish the patch. Use at your own risk, better you know what you are doing, no warranty, it just works for me YMMV etc. but here it is...


Last night I put it up on my weblog (for the RSS feeds and the entries pages. There might still be nasty bugs around, but I got those heartwarming entries in my log file:

66.249.71.70 - - [28/Mar/2006:06:14:55 +0200] "GET /blogs/ch-athens/288
HTTP/1.0" 304 1 "-" "Googlebot/2.1 (+http://www.google.com/bot.html)
...
83.171.XXX.YYY - - [28/Mar/2006:09:19:35 +0200] "GET /blogs/ch-athens/rdf91_xml 
HTTP/1.1" 304 0 "-" "NetNewsWire/2.1b17 (Mac OS X; http://ranchero.com/netnewswire/)"
...
62.1.XXX.YYY - - [28/Mar/2006:09:14:39 +0200] "GET /blogs/ch-athens/rdf91_xml 
HTTP/1.1" 304 0 "-" "Akregator/1.2.1; librss/remnants"
...
83.173.246.118 - - [28/Mar/2006:08:33:31 +0200] "GET /blogs/ch-athens/rdf91_xml 
HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; de; 
rv:1.8. 0.1) Gecko/20060111 Firefox/1.5.0.1"
As I already noticed yesterday, my own Safari (on Mac OS X 10.3.9) doesn't bother. I've seen Safari handle 304's in my log, but only on images. Either it's something I do wrong or Safari isn't up to it.

Anyway, enough of the bragging, here is the patch for conditional HTTP GET for COREBlog. Apply the patch to COREBlog.py, restart Zope (or refresh the COREBlog product if you run in debug mode). That's not enough yet, as the code still has to be called by the methods in question. The code has two new methods:

How we use these methods

In our standard COREBlog DTML methods (rdf10_xml) we wrap all the content with a DTML-IF like this:

<dtml-if "handle_modified_headers(last_mod=None, REQUEST=REQUEST)">

<dtml-else>
<!-- normal dtml-code here: -->
<dtml-comment>
##############################################################################
rdf10_xml.dtml
... etc. etc. ...
</rdf:RDF>
</dtml-if>
Notice how we have only an empty line inside the dtml-if and all the code is inside the dtml-else? When the page data hasn't changed we get away to send only those two empty lines to the client and don't need to process all the other code.

We use the same code to apply this to the other RSS feed (and any other homebrew feeds we may have. We need slightly different code for the single entry pages. I want to do these, since Googlebot regularly swipes them and they rarely change. This is how I do the entry_html:

<dtml-if
"handle_modified_headers(last_mod=DateTime(bobobase_modification_time()),
REQUEST=REQUEST)">

<dtml-else>
<!-- normal dtml-code here: -->
<dtml-comment>* Don't shor header when noheader has set.</dtml-comment>
... etc. etc. ...
</dtml-unless>
</dtml-if>
If you are using one of the ZPT skins for COREBlog (lucky you), you will have to adopt this dtml - but I don't think it will be difficult.

Posted by betabug at 10:21 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Hax0ring around with COREBlog again | Main | Spring and Comics at the Park >>
Comments
There are no comments.
Trackbacks
You can trackback to: http://betabug.ch/blogs/ch-athens/333/tbping
There are no trackbacks.
Leave a comment