Merge lp:~leonardr/lazr.restful/cache-service-root into lp:lazr.restful
| Status: | Merged |
|---|---|
| Approved by: | Gavin Panella on 2010-04-07 |
| Approved revision: | 126 |
| Merged at revision: | not available |
| Proposed branch: | lp:~leonardr/lazr.restful/cache-service-root |
| Merge into: | lp:lazr.restful |
| Diff against target: |
217 lines (+145/-2) 5 files modified
src/lazr/restful/NEWS.txt (+12/-0) src/lazr/restful/_resource.py (+30/-2) src/lazr/restful/example/base/root.py (+1/-0) src/lazr/restful/example/base/tests/root.txt (+88/-0) src/lazr/restful/interfaces/_rest.py (+14/-0) |
| To merge this branch: | bzr merge lp:~leonardr/lazr.restful/cache-service-root |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Gavin Panella | 2010-04-07 | Approve on 2010-04-13 | |
|
Review via email:
|
|||
Description of the Change
This branch gets lazr.restful to set the Cache-Control header when serving a representation of the service root. This is a big win because the service root only changes when you deploy a new version of your lazr.restful application (eg. Launchpad), but every user makes 2 requests for it every time they start up lazr.restfulclient.
There are two 'max-age' times set in the Cache-Control header: one for the latest version of the web service (which changes more often) and one for all other versions. By default, the max-age for the latest version is one hour and the max-age for all other versions is one week.
After the max-age expires, the client will make a *conditional* request to see whether the service root has changed. If it hasn't, I believe the client will update the client-side max-age and not make any requests for another hour (or week). But I need to check to make sure httplib2 actually does this.
- 127. By Leonard Richardson on 2010-04-07
-
Set the Date header as well, since httplib2 uses it to determine whether a cached representation is stale.
| Leonard Richardson (leonardr) wrote : | # |
In my experiments with lazr.restfulclient I discovered that httplib2 will ignore Cache-Control unless the Date header is also set to provide a starting point. I've updated the branch to set the Date header.
- 128. By Leonard Richardson on 2010-04-07
-
Set Cache-Control and Date even on a conditional request.
- 129. By Leonard Richardson on 2010-04-07
-
Set caching headers whether the request was conditional or not.
| Leonard Richardson (leonardr) wrote : | # |
UNfortunately, this branch breaks lazr.restfulclient due to what I believe is a bug in httplib2 (http://
- 130. By Leonard Richardson on 2010-04-13
-
Don't serve cache control headers to httplib2 clients to avoid triggering a bug in httplib2.
- 131. By Leonard Richardson on 2010-04-13
-
Removed temporary hack for testing purposes.
| Leonard Richardson (leonardr) wrote : | # |
All right, I've changed lazr.restful to avoid triggering the httplib2 bug on old versions of lazr.restfulclient. (I've tested this version of lazr.restful with an old and a new lazr.restfulclient, and they both worked, though obviously the old one didn't get the benefit of the Cache-Control headers.)
- 132. By Leonard Richardson on 2010-04-13
-
Slight refactoring.

Nice branch. Conversation from IRC:
<allenap> leonardr: Is there any way config. active_ versions could be empty?
<leonardr> allenap: no, that would prevent lazr.restful from starting up
<allenap> leonardr: Instead of having [604800, 3600], could you have a module-level constant like `HOUR = 3600 # seconds`, then the default can be specified as [7 * 24 * HOUR, 1 * HOUR]?
<leonardr> sure