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 default "time" param to parsed form (if any) #3599

Merged
merged 2 commits into from
Dec 1, 2022

Conversation

colega
Copy link
Contributor

@colega colega commented Dec 1, 2022

What this PR does

If the form was already parsed by a downstream middleware, we need to add it to that form too, otherwise it won't be available to upstream by just adding it to the url query.

This implement's @pstibrany's suggestion #3588 (comment) and copies all the tests from that PR.

Which issue(s) this PR fixes or relates to

Will make #3561 easier to review.

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

If the form was already parsed by a downstream middleware, we need to
add it to that form too, otherwise it won't be available to upstream by
just adding it to the url query.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
@colega colega requested a review from pstibrany December 1, 2022 11:41
@colega colega requested a review from a team as a code owner December 1, 2022 11:41
Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me. (But I'm not sure if it will help to solve problem in #3561 -- we will need to "reset" body in that PR, right?)

r.URL.RawQuery = q.Encode()

// If form was already parsed, add this param to the form too.
Copy link
Member

Choose a reason for hiding this comment

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

We should also mention that if form already had time parameter, this extra time value will be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I did was to add back the r.Form.Has("time") guard in this method, as otherwise we were adding the "time" to the form even if it already had it.

It only worked because I used the "Add" method, which added another value, and the old value was still being read.

Changed this and added a test case for that: a69fb16

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Thanks.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
@colega colega merged commit 2c4fc79 into main Dec 1, 2022
@colega colega deleted the add-default-instant-time-to-parsed-form branch December 1, 2022 14:46
pracucci pushed a commit that referenced this pull request Dec 1, 2022
* Add default "time" param to parsed form (if any)

If the form was already parsed by a downstream middleware, we need to
add it to that form too, otherwise it won't be available to upstream by
just adding it to the url query.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>

* Check that form doesn't have "time"

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
masonmei pushed a commit to udmire/mimir that referenced this pull request Dec 16, 2022
* Add default "time" param to parsed form (if any)

If the form was already parsed by a downstream middleware, we need to
add it to that form too, otherwise it won't be available to upstream by
just adding it to the url query.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>

* Check that form doesn't have "time"

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
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.

2 participants