-
Notifications
You must be signed in to change notification settings - Fork 281
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
How to modify req.body? #251
Comments
we need to wait till the request has been finished.
Now we will listen to the event
|
Thanks for your help. I tried what you proposed but I had the following error message on this line(proxyRequest.setHeader('x-header','my-custom-header');): |
Are you behind a corporate firewall? There is an open issue with There is a workaround mentioned on the issue. Check if that helps you resolve the issue. |
I try to modify the parameters (password) from proxyOnRequest before sending them the web server.
In my index.js, I have the following "redbird" function:
reverseProxy.register("node:5470", "web:4000", {ssl:false, useTargetHostHeader: true});
Then I call this function:
reverseProxy.proxy.on('proxyReq', changetohash.onRequest());
Inside the "changetohash" function, I want to modify the received password and send it again as parameter for the web server.
The only way to retrieve the parameter is to use this function (request.on):
export function onRequest (options) {
return function hashOnRequest(proxyRequest, request, response, options) {
if (((proxyRequest.path == "/signup") || (proxyRequest.path == "/login")) && (request.method == 'POST')) {
// Make any needed POST parameter changes
let body = '';
request.on('data', (chunk) => {
body += chunk;
}).on('end', () => {
//I try to modify the request header here
});
....
but when I wanted to modify the request header:
request.setHeader( 'content-length', body.length );
I obtain a error: "the request is already closed"
The 'content-type' is 'application/x-www-form-urlencoded'
Any ideas how to retrieve the body of my request? I tried directly request.body but it didn't work.
Thanks for your help.
The text was updated successfully, but these errors were encountered: