-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
feat(handler): implement duplicate read closer for request body #116
base: main
Are you sure you want to change the base?
Conversation
This change introduces a utility function `dupReadCloser` that allows duplicating the incoming request body reader. It is now used in the request handling loop to ensure that the request body can be consumed by multiple handlers or middleware without losing the original data.
Pull Request Test Coverage Report for Build 10055591097Details
💛 - Coveralls |
This is a useful feature, but it should not be on by default because it uses too much memory. Instead I think it should look like: handler := requests.KeepResponseBody(
requests.ToJSON(&common),
requests.ToJSON(&book),
requests.ToString(&str),
) What do you think of that? |
i think |
} | ||
|
||
var dup io.ReadCloser | ||
r.Body, dup = dupReadCloser(r.Body) |
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.
I'm not sure, but I think if one of the handlers only consumed part of the response, the subsequent handlers would only get a partial buffer.
Instead, what if on a new line between line 35 and line 36, it read the whole body into a buffer and reset the buffer on each loop?
This change introduces a utility function
dupReadCloser
that allows duplicating the incoming request body reader. It is now used in the request handling loop to ensure that the request body can be consumed by multiple handlers or middleware without losing the original data.