Improve support for working with cache headers in webapi resources.
Review Request #6773 — Created Jan. 14, 2015 and submitted
Consumers of the API that wanted to work with cache headers either
couldn't override theget()
function, or had to re-write the matching
logic. This wasn't really ideal, and made it harder to cache.Resources wanting to generate suitable ETags also had to implement their
own encoding logic.This change is the first step toward improving support for caching. It
adds a function for checking optionally-provided timestamps and ETags
against the values sent by the client (if any), and returns whether a
Not Modified can be sent back.It also adds an
encode_etag()
function that does the work of generating
a suitable ETag header value for a given string.Existing consumers that were already overriding
get_etag()
shouldn't see
any change in behavior. If they were callinggenerate_etag()
, then
they'll now get a deprecation warning giving them instructions on
callingencode_etag()
and passingencode_etag=False
togenerate_etag()
.
Future versions will remove the warning and the parameter.
Unit tests in Djblets and Review Board pass.
Tested several resources manually, looking for caching headers, and
making use of RBTools's new caching behavior to ensure that the correct
cache validation was taking place.