Improve support for working with cache headers in webapi resources.

Review Request #6773 — Created Jan. 14, 2015 and submitted

Information

Djblets
release-0.8.x
723b904...

Reviewers

Consumers of the API that wanted to work with cache headers either
couldn't override the get() 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 calling generate_etag(), then
they'll now get a deprecation warning giving them instructions on
calling encode_etag() and passing encode_etag=False to generate_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.

reviewbot
  1. Tool: Pyflakes
    Processed Files:
        djblets/webapi/resources.py
        djblets/webapi/tests.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        djblets/webapi/resources.py
        djblets/webapi/tests.py
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-0.8.x (7e82973)
Loading...