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

REVIEW NEEDED [WIP] global: add vary header to the response #273

Closed
wants to merge 2 commits into from

Conversation

kpsherva
Copy link
Contributor

@kpsherva kpsherva commented Aug 2, 2019

FOR THE REVIEWERS: this is a proposal of the solution, it will be applied not only for the get method but please first share your thoughts

( addresses #250)

Update:
The main issue seemed to be that the vary header had no effect if the etag was unchanged so the new WIP version has the etag include not only the record.revision_id but also the mimetype. It's still unclear which effect the Vary header has but without it sometimes it doesn't recognize if a change is made in the Accept header so it seems to be needed.

Requires inveniosoftware/invenio-rest#100

PAST NOTES ON THE ISSUE:

THIS IS not working fully - below my investigation
How to test:

  1. Create clean instance
  2. Install latest invenio 3.2.0a5
  3. install invenio-records-rest from this PR
    3.1. on your clean instance create custom serializer of the record f.e. application/x-custom mimetype - make sure it returns also this content type as a response example: https://github.com/kprzerwa/test-headers-instance/blob/master/my_site/records/config.py

You can use firefox for debugging - it has neat way of editing headers in the dev tools

  1. post a new record
  2. go to /records/1
  3. response should have Vary: Content-Type, Accept header - check this PR
  4. Hit again the same endpoint - the response should be cached. But it will not have the Vary header anymore! <--- I think this is where the problem is located
  5. change the Accept header to your custom application/x-custom in the request and request again the endpoint. You will get the same json response, cached, while you should get 200 status code response with x-custom content type.
    What is probably the problem here: The cached response is not adding the Vary header so the browser does not know that it should check the Accept value every time, and relies only on the combination of ETag (which is version of the record) passed to If-None-Match header and If-Modified-Since header which won't change in this case.

@@ -30,6 +30,7 @@ def view(pid, record, code=200, headers=None, links_factory=None):
response.status_code = code
response.set_etag(str(record.revision_id))
response.last_modified = record.updated
response.vary = 'Content-Type, Accept'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if anybody is relying on them, but I think it's better to use other Accept- headers too, especially Accept-Language

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since you provide Accept the Content-Type is redundant.
I would go with response.vary = 'Accept, Accept-Encoding, Accept-Language'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once this PR gets approved please use the headers like @topless is suggesting

@topless topless self-assigned this Nov 11, 2019
@@ -75,3 +76,49 @@ def test_item_get_invalid_mimetype(app, test_records):
# Check that GET with non accepted format will return 406
res = client.get(record_url(pid), headers=[('Accept', 'video/mp4')])
assert res.status_code == 406


@pytest.mark.skip
Copy link
Member

@topless topless Nov 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to enable it, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment why the test is skipped

@kpsherva kpsherva assigned kpsherva and unassigned kpsherva Nov 13, 2019
@equadon equadon self-assigned this Nov 13, 2019
@equadon equadon changed the title global: add vary header to the response [WIP] global: add vary header to the response Nov 14, 2019
@equadon equadon removed their assignment Nov 14, 2019
@kpsherva kpsherva changed the title [WIP] global: add vary header to the response REVIEW NEEDED [WIP] global: add vary header to the response Nov 14, 2019
@harunurhan
Copy link
Member

As far as I have seen, Vary doesn't seem to fix anything. Browsers would still send If-Match: <Etag> for requests with Accept: <different content-type than the request where we got the Etag in If-Match>, then server would return 304and cause the same bug.

@lnielsen lnielsen closed this Apr 2, 2024
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

Successfully merging this pull request may close these issues.

5 participants