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

Add support for multiple Etags in If-None-Match header #6219

Merged

Conversation

straight-shoota
Copy link
Member

This enhances Etag supported (which as added in #6145) to recognize multiple values in the If-None-Match header according to RFC 2732.

The header field parser is reusable outside StaticFileHandler as Headers#if_none_match and Headers#if_match.

@sdogruyol
Copy link
Member

LGTM 👍 I especially liked how it's not coupled to StaticFileHandler 💯

@straight-shoota
Copy link
Member Author

straight-shoota commented Jun 19, 2018

@sdogruyol Yeah, all this logic for handling cached requests should eventually be moved to Request/Response because it's universally usable. Any handler can just set Last-Modified and/or Etag on the response and then check the request headers against that. The only issue is that this check needs access to both request and response, so it probably needs to go on HTTP::Server::Context.

@@ -258,6 +258,73 @@ struct HTTP::Headers

forward_missing_to @hash

def if_none_match : Array(String)?
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this parsing method belongs here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wasn't sure whether this should go here or in Request. I'll move it to the latter.

Copy link
Contributor

Choose a reason for hiding this comment

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

This wasn't removed.

@straight-shoota
Copy link
Member Author

Updated

if_none_match == context.response.headers["Etag"]
if if_none_match = context.request.if_none_match
match = {"*", context.response.headers["Etag"]}
if_none_match.any? { |etag| match.includes?(etag) }
Copy link
Contributor

@Sija Sija Jul 1, 2018

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

That's different

Copy link
Contributor

@Sija Sija Jul 1, 2018

Choose a reason for hiding this comment

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

Ouch, my bad (I read it other way around), you're right.

@straight-shoota
Copy link
Member Author

Merge?

@RX14
Copy link
Contributor

RX14 commented Jul 9, 2018

need another review and bcardiff is on holiday for the next 3 weeks.

@straight-shoota
Copy link
Member Author

There are two approvals from core members... why another one?

@RX14
Copy link
Contributor

RX14 commented Jul 9, 2018

Because the PR has had extra commits since then... As soon as you add extra code, all reviews are invalidated, anything otherwise would be silly.

@asterite
Copy link
Member

asterite commented Jul 9, 2018

Approved :-P

(someone probably needs to add me as a core team member again, every two or three months I get tired of the language and remove myself, though I'm trying to manage it better now)

@straight-shoota
Copy link
Member Author

Oh, yes, that's true. My bad. @sdogruyol care for another look?

@sdogruyol
Copy link
Member

LGTM 👍 Thank you @straight-shoota 🙏

@sdogruyol sdogruyol merged commit 4771dcb into crystal-lang:master Jul 9, 2018
@sdogruyol sdogruyol added this to the Next milestone Jul 9, 2018
@straight-shoota straight-shoota deleted the jm/feature/etag-multi branch July 9, 2018 22:10
@RX14 RX14 modified the milestones: Next, 0.26.0 Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants