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

is_if_none_match_failed: check for unquoted etag in list of quoted etags. #205

Open
jkeyes opened this issue Jan 19, 2018 · 3 comments
Open

Comments

@jkeyes
Copy link

jkeyes commented Jan 19, 2018

Hey folks 👋

I ran into an issue using a local copy of drf-extensions, and I was just going to suggest a fix when I found #197 had fixed the issue by stripping quotes from etags:

if res_etag and if_none_match:
    etags = [etag.strip('"') for etag in etags]
    return res_etag in etags or '*' in etags

I was going to suggest this, which is a little bit easier to read IMO:

if res_etag and if_none_match:
    return quote_etag(res_etag) in etags or '*' in etags

I presume the fix from #197 should also have been applied to is_if_match_failed too.

@sakhunzai
Copy link

I agree with your suggestion to fix is_if_match_failed. I spent hours having "Precondition Failed" on a PUT request. This means both functions require striped etags therefore, they should be done out side both functions, probably before calling both functions or parse_etags function should return striped tags ?

@sakhunzai
Copy link

I also see another issue with line:
etags = [etag.strip('"') for etag in etags]

if we have weak etag its not striped properly and matching will fail e.g

if_match='W/"6ff096757676aaecfe35d932aa04e4f8"'
res_etag='6ff096757676aaecfe35d932aa04e4f8'
etags=['W/"6ff096757676aaecfe35d932aa04e4f8"']
etags = [etag.strip('"') for etag in etags]
#estags : ['W/"6ff096757676aaecfe35d932aa04e4f8']
# A better option seems 
etags = [etag.strip('W/"') for etag in etags]
# ['6ff096757676aaecfe35d932aa04e4f8']

@sakhunzai
Copy link

I am not sure what will be consequences given 1.11 documentation read as:

Changed in Django 1.11:

In older versions, the return value from etag_func() was interpreted as the unquoted part of the ETag. That prevented the use of weak ETags, which have the format W/"". The return value is now expected to be an ETag as defined by the specification (including the quotes), although the unquoted format is also accepted for backwards compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants