When serving static files, this adds a Last-Modified header to responses. It also adds the ability to use the If-Modified-Since header from HTTP requests, and sends back a 304 response if appropriate.
Note that in my testing, it's hard to get a browser to actually send the If-Modified-Since header in real-world usage. In Chrome, if you uncheck "Disable Cache" in the network panel (of the dev tools), then reload the page, it will simply retrieve the files from the browser's memory cache. I think if you wait for a long enough period of time (at least several minutes), it will make a request with If-Modified-Since and then receive a 304 response.
This PR also changes all instances of DataSource* to a shared_ptr<DataSource> (and same for FileDataSource* and InMemoryDataSource*) because there were some places where managing the lifetime was getting pretty complicated. Switching to a shared_ptr simplifies it greatly.
When serving static files, this adds a
Last-Modified
header to responses. It also adds the ability to use theIf-Modified-Since
header from HTTP requests, and sends back a 304 response if appropriate.Note that in my testing, it's hard to get a browser to actually send the
If-Modified-Since
header in real-world usage. In Chrome, if you uncheck "Disable Cache" in the network panel (of the dev tools), then reload the page, it will simply retrieve the files from the browser's memory cache. I think if you wait for a long enough period of time (at least several minutes), it will make a request withIf-Modified-Since
and then receive a 304 response.For better caching, I think there needs to be
Cache-Control
andETag
headers, as described here: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#validating_cached_responses_with_etagsThis PR also changes all instances of
DataSource*
to ashared_ptr<DataSource>
(and same forFileDataSource*
andInMemoryDataSource*
) because there were some places where managing the lifetime was getting pretty complicated. Switching to ashared_ptr
simplifies it greatly.