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

fix: restore req body #397

Merged
merged 1 commit into from
Feb 26, 2024
Merged

fix: restore req body #397

merged 1 commit into from
Feb 26, 2024

Conversation

sigua-cs
Copy link
Collaborator

@sigua-cs sigua-cs commented Feb 3, 2024

Description

Fix restore original req.Body

Pull request type

implements #336

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Checklist

  • Linter passes correctly
  • Add tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary

Does this introduce a breaking change?

  • Yes
  • No

Further comments

@sigua-cs sigua-cs added the bug label Feb 3, 2024
@sigua-cs sigua-cs self-assigned this Feb 3, 2024
Copy link

render bot commented Feb 3, 2024

Copy link
Collaborator

@mga-chka mga-chka left a comment

Choose a reason for hiding this comment

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

Is there an easy way to add a test in order to assess the before/after change behavior (to ensure we don't have a regression in the future)?

proxy.go Outdated
// update body
rp(rw, req)

// Restore req.Body after it's consumed by 'rp' for potential reuse.
req.Body = io.NopCloser(bytes.NewBuffer(body))
req.Body.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do you have a call to Close() here and there? https://github.com/ContentSquare/chproxy/pull/397/files#diff-8b7f25bac2ae04c2ce2abb628c6aa28103fd113103a62f3e9d232fa995684915R111

I don't know what should be done, but it doesn't look logic to have inconsistencies for the same use case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right. This one was at the beginning. I'll check if can be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

req.Body.Close() appears in few places. Maybe, better to refactor it in a separate PR?

@sigua-cs
Copy link
Collaborator Author

sigua-cs commented Feb 5, 2024

Is there an easy way to add a test in order to assess the before/after change behavior (to ensure we don't have a regression in the future)?

I'll try

proxy_test.go Outdated
}

//func TestRequestBody(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you remove the commented code?

@sigua-cs sigua-cs force-pushed the issue/336_restore-req-body branch 6 times, most recently from d5d10c2 to 245d3ea Compare February 23, 2024 13:10
@mga-chka mga-chka merged commit b835b2d into master Feb 26, 2024
4 of 5 checks passed
@mga-chka mga-chka deleted the issue/336_restore-req-body branch February 26, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

2 participants