-
Notifications
You must be signed in to change notification settings - Fork 2k
Why writeStatusCode is using res.writeHead() instead of res.statusCode? #680
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
@banduk could you give me an example of how you are using it? |
Sure, here's my piece of code. With
|
@banduk in this case its the app that you are proxying to that would have already written the headers, not Would allowing it to be possible to inject a transform stream before returning the response solve your problem? |
@jcrugzz, that's what thought; that this is not what I'm using |
@banduk well what i realized is that any of these custom transform streams would need to also inherit from an actual request and response object and automatically pass along headers on('pipe'). There needs to be a module around this to make it possible. I believe it would allow you to modify the header as there wouldn't be a race condition on whether they were sent already or not. |
@jcrugzz So I'm sure this solves my problem, yes.. |
@mbanduk there is no way to do that currently using this module since we strictly do a reverse proxy and thats it. You'd have to replicate the logic that you need in the reverse proxy until these hooks exist. |
@jcrugzz , this code allow me to do what I want. Would it be a good alternative? ...
(options.buffer || req).pipe(proxyReq);
proxyReq.on('response', function(proxyRes) {
if(server) { server.emit('proxyRes', proxyRes, req, res); }
for(var i=0; i < web_o.length; i++) {
if(web_o[i](req, res, proxyRes)) { break; }
}
// Allow us to listen when the proxy has completed
proxyRes.on('end', function () {
if (!clb) {
server.emit('end', req, res, proxyRes);
}
})
// Here are the changes
if(options.after && typeof options.after === 'function' && options.after.super_ === Transform){
var after = new options.after({req: req, res: res, proxyRes: proxyRes});
proxyRes.pipe(after).pipe(res);
}
else{
proxyRes.pipe(res);
}
... and then calling: function SignRequest(options) {
if (!(this instanceof SignRequest))
return new SignRequest(options);
Transform.call(this, options);
this.options = options;
}
util.inherits(SignRequest, Transform);
SignRequest.prototype._transform = function(chunk, encoding, done) {
sign(this.options.req, this.options.res, this.options.proxyRes);
this.push(this.options.proxyRes.body);
done();
};
app.all('*',
proxy.web(req, res, {
target: {
protocol: appProtocol,
host: appHost,
port: appPort
},
after: SignRequest
});
); |
Hi guys,
I was trying to sign a header (using its contents) but could not find a good way.
But setting the statusCode variable instead of using res.statusCode() function did the trick.
I was just wondering if there`s a reason why this is being done this way.
The text was updated successfully, but these errors were encountered: