views:

54

answers:

1

I am in need of education about browsers and how they send up dates in HTTP headers. I am worried that I will not be able to do a string comparison if the user has a different browser or localization.

Currently, I have code something like this to handle requests:

DateTime dt = getLastModified(someResourceHandle);
if(Request.Headers["If-Modified-Since"] == dt.ToString("R")/*RFC1123*/) { 
     // return HTTP 304 (Not Modified)
} else {
     getFullResource(someResourceHandle);
}

Goal: I don't want it to break.

So I inspected the request headers from a couple browsers:

When I use IE, with English as my language:

Accept-Language: en-us
If-Modified-Since: Tue, 30 Jun 2009 15:52:19 GMT

When I use IE, with French (Belgium) as my language (I would have expected "mar" instead of "Tue"):

Accept-Language: fr-be
If-Modified-Since: Tue, 30 Jun 2009 15:52:19 GMT

No matter what, I get this from Firefox:

Accept-Language: en-us,en;q=0.5
If-Modified-Since: Tue, 30 Jun 2009 15:52:19 GMT

This looks good for me, since it appears that the dates are all using the English abbreviations and a single format (RFC 1123) - but I'm not sure that this holds for all major browsers and for all globalizations and operating systems (I only have access to test on a Windows machine).

Am I doing it right?

+2  A: 

Yes this does hold for all browsers. Its the HTTP spec which establishes the format of this header and as far as I know all browsers are compliant in this case.

This If-Modified-Since and Last-Modified headers are not affected by Accept-Language (which refers to the body not headers).

AnthonyWJones