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

Sets request's GetBody field on create wrapper #207

Merged
merged 2 commits into from
Nov 8, 2023

Conversation

sebasslash
Copy link
Contributor

Closes #121

This commit addresses two key issues:

  • Upon receiving a temporary redirect, net/http will only preserve the request's body if GetBody() is defined (third to last sentence in the paragraph).
  • Upon receiving a GOAWAY frame, the client will create a new connection. We define GetBody() in order to reuse the body sent in the last stream on the now terminated connection.

Not entirely sure why the fix was never merged, but here we are :) Credits to @rgb-24bit

This commit addresses two key issues:
- Upon receiving a temporary redirect, net/http will only preserve the request's body if GetBody() is defined.
- Upon receiving a GOAWAY frame, the client will create a new connection. We define GetBody() in order to reuse the body sent in the last stream on the now terminated connection.
@sebasslash sebasslash requested review from a team, dekimsey and randyhdev November 6, 2023 16:33
Copy link

@dekimsey dekimsey left a comment

Choose a reason for hiding this comment

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

I was wondering if we needed to test for 307/308 response codes before setting the GetBody, but it looks like Client.Do is pretty clear that it'll only invoke this helper if it thinks it should. So that works for me!

I 💯 appreciate the additional tests! Thank you

@sebasslash sebasslash merged commit 309c58e into main Nov 8, 2023
3 checks passed
Copy link

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

I am a little late on the review but thought I would share my findings which were not blocking anyway


func TestClient_RedirectWithBody(t *testing.T) {
var redirects int32
// Mock server which always responds 200.
Copy link

Choose a reason for hiding this comment

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

Not technically true

w.Header().Set("Location", "/target")
w.WriteHeader(http.StatusTemporaryRedirect)
case "/target":
atomic.AddInt32(&redirects, 1)
Copy link

Choose a reason for hiding this comment

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

Should this test that the body was received?

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.

Request wrapper make standard request GetBody property always nil
3 participants