-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Added veryfication if path contains query params and add them to path header #6466
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,10 +57,19 @@ bool Utility::Url::initialize(absl::string_view absolute_url) { | |
| // RFC allows the absolute-uri to not end in /, but the absolute path form | ||
| // must start with | ||
| if ((u.field_set & (1 << UF_PATH)) == (1 << UF_PATH) && u.field_data[UF_PATH].len > 0) { | ||
| path_ = absl::string_view(absolute_url.data() + u.field_data[UF_PATH].off, | ||
| u.field_data[UF_PATH].len); | ||
| uint64_t path_len = u.field_data[UF_PATH].len; | ||
| if ((u.field_set & (1 << UF_QUERY)) == (1 << UF_QUERY) && u.field_data[UF_QUERY].len > 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My one remaining question - is it possible for UF_QUERY to be set and u.field_data[UF_QUERY].len == 0? If path length is 0 we substitute a hard-coded "/". If the +1 for length is due to the "?" being considered the delimiter I'd like to make sure that http://foo.com? would get proxied without losing the ?. Can you add a test for that corner case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I investigated it a bit. for url: http://foo.com/ -> UF_PATH bit is set and len = 1
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh nice, thanks for digging into this, and adding the extra corner case testing! So while this is clearly an improvement over what we have, I'm still pretty uncomfortable with /? being normalized to / unless it's illegal by the spec. I'd be fine
I'd lean towards 2. @mattklein123 thoughts/preferences?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (2) SGTM, agreed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. Merged because I'd prefer the clearly-better-behavior to make next week's release. Lukasz, thanks so much for tackling this. Bonus points if you'd be willing to poke through the spec or sync with @PiotrSikora on expected behavior for /? and tackle that in a follow-up :-) |
||
| path_len += 1 + u.field_data[UF_QUERY].len; | ||
| } | ||
| path_and_query_params_ = | ||
| absl::string_view(absolute_url.data() + u.field_data[UF_PATH].off, path_len); | ||
| } else if ((u.field_set & (1 << UF_QUERY)) == (1 << UF_QUERY) && u.field_data[UF_QUERY].len > 0) { | ||
| // Http parser skips question mark and starts count from first character after ? | ||
| // so we need to move left by one | ||
| path_and_query_params_ = absl::string_view(absolute_url.data() + u.field_data[UF_QUERY].off - 1, | ||
| u.field_data[UF_QUERY].len + 1); | ||
| } else { | ||
| path_ = absl::string_view(kDefaultPath, 1); | ||
| path_and_query_params_ = absl::string_view(kDefaultPath, 1); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a bit easier to see the differences here if we split out length settings, e.g.
uint64_t path_len = u.field_data[UF_PATH].len;
if ([query param exists) {
path_len += 1 + u.field_data[UF_PATH].len
}
path_ = path_ = absl::string_view(absolute_url.data() + u.field_data[UF_PATH].off, path_len);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it looks much better.