-
Notifications
You must be signed in to change notification settings - Fork 2k
Unable to set cookies / write headers from proxy #445
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
Comments
This isn't going to work because |
I suggest to close this issue since we can quite easily achieve replacing of headers by "emulating" express middlewere and replacing setHeader. var http = require('http'),
httpProxy = require('http-proxy'),
static = require('node-static');
httpProxy.createServer(function(req, res, next){
//this code will replace all set-cookie headers to ONE header that u want
//if there will be 2 set-cookie headers
//result will be 1 set-cookie:a=b header
var _setHeader = res.setHeader.bind(res);
res.setHeader = function(name, value) {
if (name && name.toLowerCase() == "set-cookie") {
return _setHeader("set-cookie", "a=b");
} else {
return _setHeader(name, value);
}
}
next();
},function (req, res, proxy) {
//usuall code
proxy.proxyRequest(req, res, {
host: 'someserver.com',
port: 80
});
}).listen(8000); |
@AiBoy, I tried your solution on a recent boilerplate (since that was written in 2013) and while I'm able to modify/override any header property, I can't get a cookie to save under resources, jessionid in particular. |
Is there any solution with cookies received from a proxied subdomain, which also contain the "domain" attribute? We cannot authenticate from localhost (we are using webpack-dev-server) because of this problem. The 'domain' attribute for the received cookie is different from 'localhost' (obviously) and this causes the authentication to not work on the next call. Is there any solution or trick to this problem? (i.e. automatically changing the "domain" attribute value through a proxy rule or code?) Thanks! |
Actually... is this PR what I am really looking for? If yes, can you please add it to the library? Thanks! |
What status is this feature ? is this still going on? |
I am trying to write a header on the response object from within the proxy:
And http fails with "Cannot write header/s after they have been written." Reverse proxy documentation says nothing about setting cookies. What am I doing wrong?
The text was updated successfully, but these errors were encountered: