Furrygoat uses an ASP.NET page that is dynamically created off of a source XML file for rendering RSS requests. My original thinking was that by building an RSS file when it was requested, I could support multiple versions of RSS without too much trouble. Of course, Brad noticed that I was lazy and didn’t support ETag.

I decided to do implement an ETag scheme based on the last modification date/time of the xml file that I was using for the ASP page’s source. When the page loads, it generates the ETag value, and then checks it against the request’s If-None-Match header. If the value matches, then no content has changed, and I return a 304. Otherwise, I append the information for Last-Modified and ETag to the response headers. Not to much work after all:

void Page_Load(object sender, EventArgs e) {
// Generate ETAG Values
DateTime dt = File.GetLastWriteTimeUtc(Server.MapPath("someRssFeedSource.xml"));
string curDate = dt.ToString("r", DateTimeFormatInfo.InvariantInfo);
string eTagDate = "\""+dt.ToString("s", DateTimeFormatInfo.InvariantInfo)+"\"";

Response.AppendHeader("ETag", eTagDate);

// Check the ETAG Value first
string incomingEtag = Request.Headers["If-None-Match"];
if(String.Compare(incomingEtag, eTagDate) == 0) {
Response.StatusCode = 304;
return;
}

// Setup the cached response
Response.AppendHeader(”Last-Modified”, curDate);

// Continue processing…….
}


No Comments

No comments yet.

Sorry, the comment form is closed at this time.