-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
http: introduce getAllHeaders()
#772
Conversation
Users should not have to access private attributes like res._headers in order to get all the headers in a request. Define a method getAllHeaders to return an object which is a copy of res._headers Fixes: nodejs/node-v0.x-archive#3992 PR-URL: nodejs#170 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
This replaces the faulty test with a modified version of test-http-header-read.
@@ -381,6 +381,15 @@ Example: | |||
|
|||
var contentType = response.getHeader('content-type'); | |||
|
|||
### response.getAllHeaders() | |||
|
|||
Reads out all headers that are already been queued but not yet sent to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that are
should be that have
The test doesn't quite cover what I'd like it to cover: var util = require('util');
var http = require('http');
var common = require('../common');
var headers;
var rando = Math.random();
var expected = util._extend({}, {
'X-Random-Thing': rando,
/* other values */
});
var server = http.createServer(function(req, res) {
res.setHeader('X-Random-Thing', rando);
headers = res.getAllHeaders();
res.end('hello');
assert.strictEqual(res.getAllHeaders(), null);
});
server.listen(common.PORT, function() {
http.get({port: common.PORT}, function(resp) {
assert.deepEqual(response.headers, expected);
server.close();
});
}); Specifically. I'm looking for it to be able to pick up on the automatic headers as well as the explicitly set ones. |
@chrisdickinson According to the previous test I'll update the rest though, |
@Fishrock123 Thanks for doing this. I haven't had the time recently to finish this test. |
I talked extensively about this on irc with @chrisdickinson today on if and how this should return the implicit headers, and now I'm actually sure how much I like the idea of this. I think the only way to keep it sane would be:
|
ping @chrisdickinson, how do you feel about my proposed changes as per the above? |
Would it be possible to do a |
I'm not sure I understand? Do you mean just generate on getter? That seems less reliable. |
Going to close (for now?). I'm not too confident about changing |
How can we get the |
OK I have a working solution for now. See my comment here #28302 (comment). |
Succeeds the patch proposed in #170
R=@chrisdickinson, cc @iankronquist