Skip to content

Fix event listener on "proxyReq" #77

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

Closed

Conversation

casheeeewnuts
Copy link

@casheeeewnuts casheeeewnuts commented Oct 25, 2022

Current code has a problem that calling proxyReq.end() method don't wait proxyReq.write(req.body).
To fix, proxyReq.end() must be called in callback that be passed second argument with proxyReq.write().

Another solution is piping the original request to proxy with req.pipe(). By use it, dont need to use JSON.stringify() to serialize request body.
So, performance improvement expected.

And more type-safe.

if (hasRequestBodyMethods.indexOf(req.method as string) >= 0 && typeof req.body === "string") {
proxyReq.write(req.body);
proxyReq.end();
.once("proxyReq", ((proxyReq: http.ClientRequest, req: http.IncomingMessage): void => {
Copy link
Owner

Choose a reason for hiding this comment

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

Hi @casheeeewnuts
Thanks for your PR

Serializing req.body was used to solve the problem(#3) of sending HTTP Request Body, but it seems that it is no longer needed(#33). 😀

Thanks :)

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