How to update location in for http call
Asked Answered
J

1

6

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

Jozef answered 20/8, 2015 at 6:16 Comment(1)
Do you want to redirect the web browser to another URL, is that what you want?Hosea
S
2

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.

Spinescent answered 26/8, 2015 at 6:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.