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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
rawHeaders is an empty array in the response #354
Comments
@mtt87 if it's part of the public API then there's no reason for Nock not to include it. PR is welcome :) |
@pgte I'm not that good but I'm trying, can you point me in the right direction? 馃槃 As far as I can see you deal with the headers here: if (headers !== undefined) {
this.headers = {};
this.rawHeaders = [];
// makes sure all keys in headers are in lower case
for (var key2 in headers) {
if (headers.hasOwnProperty(key2)) {
this.headers[key2.toLowerCase()] = headers[key2];
}
}
// this is what I've added
for (var key3 in this.headers) {
this.rawHeaders.push(key3, headers[key3]);
}
} Thanks |
I think I've found it and seems like it's working for me var response = new IncomingMessage(new EventEmitter()),
requestBodyBuffers = [],
originalInterceptors = interceptors,
aborted,
emitError,
end,
ended,
headers,
rawHeaders,
keys,
key,
i,
l;
...
response.headers = interceptor.headers || {};
response.rawHeaders = interceptor.rawHeaders || {}; I'm gonna write a test now 馃槃 |
Problem with this test test("reply headers as function work", function(t) {
var scope = nock('http://example.com')
.get('/')
.reply(200, 'boo!', {
'X-My-Headers': function (req, res, body) {
return body.toString();
}
});
var req = http.get({
host: 'example.com',
path: '/'
}, function (res) {
t.equivalent(res.headers, {'x-my-headers': 'boo!'}); // 66
t.equivalent(res.rawHeaders, ['x-my-headers', 'boo!']); // 67
t.end();
});
});
Because res.rawHeaders = [ 'x-my-headers', [Function] ] Can you help me and tell me where are the headers as function converted into value? |
Fix landed on v2.10.0 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it鈥檚 related. Thank you! |
Hi! 馃槃
I'm using Popsicle https://github.com/blakeembrey/popsicle and using Nock for testing but seems like there is a problem, Popsicle expects
rawHeaders
and Nock is setting this array to empty so I can't test response headers.Is this a bug or there is a reason behind this choice?
I think Nock shouldn't set this array to empty.
Node API:
https://nodejs.org/api/http.html#http_message_headers
Thanks 馃槃
The text was updated successfully, but these errors were encountered: