Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update location in for http call

Im using the reverse proxy from the following link, currently Im getting some location and I want to update it(the location), How can I do that?

proxy.on('proxyRes', function (proxyRes, req, res) {

res.headers.location = 'http:/a/b/'

});

and I need to change it for example to be

res.headers.location = 'http:/c/d/' I will handle the logic how to change the URL but I want to know how to update it...

https://github.com/nodejitsu/node-http-proxy

like image 779
07_05_GuyT Avatar asked Aug 20 '15 06:08

07_05_GuyT


1 Answers

in order to change the location headers try using res.location()

proxy.on('proxyRes', function (proxyRes, req, res) {

 res.location('http:/c/d/');

});

res.location just sets the response header. It does not set a response status code or close the response, so you can write a response body it you want, and you have to call res.end() on your own after.

Reference: Express Location , the source

Hope this helps.

like image 200
SUNDARRAJAN K Avatar answered Oct 13 '22 10:10

SUNDARRAJAN K