I developed a nodejs api to listen to http requests then add some header values and forward it to another Restful service in different server. When the response returns, I will forward same response to requester without doing any modification. so basically this api will work as a forward proxy.
I used below code to forward the response to requester, It returns data however one of our response includes an attachment(pdf file) which will always receive to requester as an empty file/corrupted. Can anybody please help me to resolve this?
app.use('/', function(req, res, next){
var request = require('request');
var url={{someurl}}
var option = {
method:req.method,
json:data,
headers:{
"Content-Type": "application/json",
"Cookie":result
};
};
request(URL, option, function (error, response, body) {
if (error) {
res.status("500").send(error);
res.end(err);
}else{
if (req.method=='GET'){
res.set(response.headers);
}
res.status(response.statusCode).send(body);
res.end(response);
}
})
});