Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix: Implemented Conditional GET using etags #1333
On non-range requests, kitura StaticFileServer will never send HTTP 304 NOT MODIFIED response, even if client already has the latest version of a resource. It will send the entire file instead, which is a waste of resources. Additionally, a documentation error regarding the max-age header parameter was fixed.
A check was added to see if the file's Etag matched the request's corresponding "If-None-Match" parameter. If they are equal, the server will respond with HTTP 304 NOT MODIFIED. Otherwise it will still send the file.
Motivation and Context
See issue #1332. In some use cases, a browser may request the same resource on many different pages, or multiple times for a number of other reasons. Using the max-age parameter is inadequate because it does not allow the developer to update a resource at any time without clients continuing to use an outdated version of a resource. I created this because I need my server to be as efficient as possible, and under my use case this change results in a significant resource savings.
How Has This Been Tested?
I have tested the code on a personal project (on a mac using a browser on the same computer). It should not affect other areas of the code.