Comment 7 for bug 274815

Revision history for this message
Leonard Richardson (leonardr) wrote : Re: Cached binary files aren't retrieved from cache

After some false starts I've discovered the real reason why this test is so difficult. Here's my analysis. This is not written very well but I need to write it down because I keep forgetting parts of it.

First, let's agree to ignore the Cache-Control wrinkle. That's a complicating factor that only affects how long it is until the problem shows up.

Consider a resource that serves an ETag when you GET it. The first time the client GETs it, lazr.restfulclient stores the ETag and httplib2 caches the representation. The second time it GETs that resource, it sends the ETag as If-None-Match. That is, it makes a conditional request. The conditional request either fails (in which case the response code is 200) or it succeeds (in which case raising an HTTPError is the correct behavior).

Now consider a file from the Launchpad librarian. When you GET this resource it serves Last-Modified but not ETag. lazr.restfulclient ignores Last-Modified, but httplib2 sends Last-Modified. The response is 304, and httplib2 retrieves the document from the cache.

But lazr.restfulclient doesn't think it's making a conditional request! Remember, there was no ETag. lazr.restfulclient gets the 304 and raises an exception, as it does in the 'normal' base. But since the code didn't think it was making a conditional request, there's no code to catch this exception and handle it correctly.

Every one of the lazr.restful resources serves an ETag, so I can't duplicate this problem with our existing lazr.restful example service. The right thing to do is to create a strange librarian-like resource in the example service that serves Last-Modified but not ETag. I might be able to make the fake librarian do this.

Then I can test the fix given above.

While diagnosing this I considered whether we should have lazr.restfulclient send If-Modified-Since in addition to If-None-Match. I don't think that makes sense right now: it would make sense if we had an http_modified_since field in entires, in addition to the http_etag we have in entries now. Until then, I think it makes perfect sense to have httplib2 handle If-Modified-Since. We're not wasting any bandwidth now.