Simon Fell > Its just code > BDG to Etags

Sunday, May 19, 2002

Simon wrote: "Here's a suggestion for people writing RSS aggregators, use the HTTP/1.1 Etag and If-None-Match headers so that you only fetch the feed if its changed."

I understand the goal, but not how the implementation would work. Maybe Simon's willing to post some sample header values to shed some light on the idea... [Jake's Radio 'Blog]

Sure, the server response may contain an ETag header, you save this away ascociated with the URL, then on subsequent requests for that url, you include a If-None-Match header with the etag value. If the contents haven't changed, then the server will reply with a 304 Not Modified.

here's an initial request where we don't have a previously obtained etag

GET /weblog/rss.xml HTTP/1.1
Host:
www.pocketsoap.com

And the response

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Mon, 20 May 2002 03:08:54 GMT
Content-Type: text/xml
Accept-Ranges: bytes
Last-Modified: Mon, 20 May 2002 00:20:54 GMT
ETag: "e8d8993494ffc11:b8e"
Content-Length: 9548

<?xml version="1.0"?>
<!-- RSS generated by Radio UserLand v8.0.5 ....

Extract the ETag value, then next time you want that URL, you add the If-None-Match header,

GET /weblog/rss.xml HTTP/1.1
If-None-Match: "e8d8993494ffc11:b8e"
Host:
www.pocketsoap.com

If the file hasn't changed, then it'll still have the same ETag, which matches, so there's no response, just a 304

HTTP/1.1 304 Not Modified
Server: Microsoft-IIS/5.0
Date: Mon, 20 May 2002 03:08:39 GMT
ETag: "e8d8993494ffc11:b8e"
Content-Length: 0

If however the resource has changed, the server assigns it a different Etag, so it no long matches the etag in the request, the server will send the new version

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Mon, 20 May 2002 03:09:54 GMT
Content-Type: text/xml
Accept-Ranges: bytes
Last-Modified: Mon, 20 May 2002 03:09:51 GMT
ETag: "1238993494ffc11:b8f"
Content-Length: 9548

<?xml version="1.0"?>
<!-- RSS generated by Radio UserLand v8.0.5 ....