diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2018-08-14 19:25:05 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-14 19:25:05 -0400 |
| commit | 157a4e409551f4008e15e38fd3991aadcd8abbcd (patch) | |
| tree | b4d9ebde516261b4aa6453678c781bfe1c65a92c /cherrypy/lib | |
| parent | 8090b79ea406d9d5f909432267f81ce90542c2dd (diff) | |
| parent | 94c31e8c1d8851584210afbc2b6e1d4882c48c87 (diff) | |
| download | cherrypy-git-17.2.0.tar.gz | |
Merge pull request #1692 from SURFscz/masterv17.2.0
Fix static file cached 304 response
Diffstat (limited to 'cherrypy/lib')
| -rw-r--r-- | cherrypy/lib/caching.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/cherrypy/lib/caching.py b/cherrypy/lib/caching.py index aa265164..fed325a6 100644 --- a/cherrypy/lib/caching.py +++ b/cherrypy/lib/caching.py @@ -405,10 +405,19 @@ def tee_output(): output.append(chunk) yield chunk - # save the cache data + # Save the cache data, but only if the body isn't empty. + # e.g. a 304 Not Modified on a static file response will + # have an empty body. + # If the body is empty, delete the cache because it + # contains a stale Threading._Event object that will + # stall all consecutive requests until the _Event times + # out body = b''.join(output) - cherrypy._cache.put((response.status, response.headers or {}, - body, response.time), len(body)) + if not body: + cherrypy._cache.delete() + else: + cherrypy._cache.put((response.status, response.headers or {}, + body, response.time), len(body)) response = cherrypy.serving.response response.body = tee(response.body) |
