Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a webbrowser send If-Modified-Since?

I'm serving a dynamically created recent.rss via python flask and naturally that way it is always sent via 200 OK. I was going to fix this by setting the header Expires a week into the future and checking if the browser sent If-Modified-Since.

If so (after comparing dates) I would just do return nothing, 304 instead of return response, but according to Firebug and request.environ my browser just never sends If-Modified-Since for that ressource.

I know I could just save the data to a file and serve it as a real static file using a webserver, but I might end up really needing to serve static files via WSGI and even if not I'd like to know why this doesn't work.

Thanks for any help.

like image 865
Steffen Avatar asked Dec 16 '22 10:12

Steffen


1 Answers

RFC 2616 HTTP/1.1 has this note in 14.25 If-Modified-Since:

When handling an If-Modified-Since header field, some servers will use an exact date comparison function, rather than a less-than function, for deciding whether to send a 304 (Not Modified) response. To get best results when sending an If-Modified-Since header field for cache validation, clients are advised to use the exact date string received in a previous Last-Modified header field whenever possible.

This indicates that you should send a Last-Modified header when you expect/want the client to send If-Modified-Since.

like image 75
Joachim Sauer Avatar answered Dec 31 '22 04:12

Joachim Sauer