diff --git a/lib/request_overrider.js b/lib/request_overrider.js index b0d55c7f9..3114c30c8 100644 --- a/lib/request_overrider.js +++ b/lib/request_overrider.js @@ -471,17 +471,17 @@ function RequestOverrider(req, options, interceptors, remove, cb) { return } - /// response.client.authorized = true - /// fixes https://github.com/pgte/nock/issues/158 - response.client = _.extend(response.client || {}, { - authorized: true, - }) - - // Account for updates to Node.js response interface - // cf https://github.com/request/request/pull/1615 - response.socket = _.extend(response.socket || {}, { - authorized: true, - }) + // `IncomingMessage.client` is an undocumented alias for + // `IncomingMessage.socket`. Assigning it here may help with + // compatibility, including with very old versions of `request` which + // inspect `response.client.authorized`. Modern versions of request + // inspect `response.socket.authorized` which is set to true in our + // `Socket` constructor. + // https://github.com/pgte/nock/issues/158 + // https://github.com/request/request/pull/1615 + // https://nodejs.org/api/http.html#http_response_socket + // https://github.com/nodejs/node/blob/2e613a9c301165d121b19b86e382860323abc22f/lib/_http_incoming.js#L67 + response.client = response.socket // Evaluate functional headers. const evaluatedHeaders = {} diff --git a/lib/socket.js b/lib/socket.js index c63de305f..34911ad0f 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -14,6 +14,7 @@ function Socket(options) { EventEmitter.apply(this) if (options.proto === 'https') { + // https://github.com/nock/nock/issues/158 this.authorized = true } diff --git a/tests/test_intercept.js b/tests/test_intercept.js index 4db3b6b7e..4b73cef8d 100644 --- a/tests/test_intercept.js +++ b/tests/test_intercept.js @@ -3828,6 +3828,7 @@ test('mocking succeeds even when host request header is not specified', t => { ) }) +// https://github.com/nock/nock/issues/158 test('mikeal/request with strictSSL: true', t => { nock('https://strictssl.com') .post('/what')