Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last modified time should be skipped when etag check fails. #1132

Open
danny0838 opened this issue Feb 28, 2019 · 1 comment · May be fixed by #1154
Open

Last modified time should be skipped when etag check fails. #1132

danny0838 opened this issue Feb 28, 2019 · 1 comment · May be fixed by #1154
Labels
Bug This issue is an actual confirmed bug that needs fixing

Comments

@danny0838
Copy link

It is possible that a change to file/directory causes a etag change and no last modified time change. For example:

  1. Create folder A.
  2. Create folder B.
  3. Visit folder B.
  4. Rename folder B to C, and then A to B.
  5. Visit folder B (previous folder A).

At step 5, the client sents HTTP_IF_MODIFIED_SINCE header with the last modified time of folder B in step 2. Since the last modified time of folder A is less than B, the server will send 304 back, which is an error since the folder is actually changed.

To fix this, we should skip checking for 304 if the client already sends an etag which does not return 304. Here's a patch to fix this:

diff --git a/bottle.py b/bottle.py
index 0b22f2e..9ac9ee5 100755
--- a/bottle.py
+++ b/bottle.py
@@ -2914,11 +2914,12 @@ def static_file(filename, root,
         if check and check == etag:
             return HTTPResponse(status=304, **headers)
 
-    ims = getenv('HTTP_IF_MODIFIED_SINCE')
-    if ims:
-        ims = parse_date(ims.split(";")[0].strip())
-    if ims is not None and ims >= int(stats.st_mtime):
-        return HTTPResponse(status=304, **headers)
+    if not (etag and check):
+        ims = getenv('HTTP_IF_MODIFIED_SINCE')
+        if ims:
+            ims = parse_date(ims.split(";")[0].strip())
+        if ims is not None and ims >= int(stats.st_mtime):
+            return HTTPResponse(status=304, **headers)
 
     body = '' if request.method == 'HEAD' else open(filename, 'rb')
@defnull defnull added the Bug This issue is an actual confirmed bug that needs fixing label May 28, 2019
@Hanaasagi
Copy link
Contributor

I think this is right. Other frameworks do the same things, like Tornado
https://github.com/tornadoweb/tornado/blob/8e5ecad25ea86d52245a9587fd454613f03c7fb8/tornado/web.py#L2707-L2709

And I think I can reslove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This issue is an actual confirmed bug that needs fixing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants