Skip to content

Leave rawHeaders case untouched on nock's replies #707

@hugoduraes

Description

@hugoduraes

I've noticed that nock is creating rawHeaders from the response headers object, which keys are lowercased. This is causing rawHeaders keys to also be lowercased, which I think is wrong because nock's rawHeaders may be getting different from the real response's rawHeaders. I believe rawHeaders case should be returned untouched.

This is the code responsible for it on lib/interceptor.js:62:

//  We use lower-case headers throughout Nock.
headers = common.headersFieldNamesToLowerCase(headers);

_.defaults(this.options, this.scope.scopeOptions);

if (this.scope._defaultReplyHeaders) {
    headers = headers || {};
    headers = mixin(this.scope._defaultReplyHeaders, headers);
}

if (this.scope.date) {
    headers = headers || {};
    headers['date'] = this.scope.date.toUTCString();
}

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.rawHeaders.push(key2);
            this.rawHeaders.push(headers[key2]);
        }
    }
    debug('reply.rawHeaders:', this.rawHeaders);
}

Why don't nock builds the headers object based on the rawHeaders array? Like that rawHeaders would remain untouched and headers could still have lowercased keys.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions