Skip to content
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

feat(request_overrider): Set IncomingMessage.client for parity with real requests #1385

Merged
merged 1 commit into from Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/request_overrider.js
Expand Up @@ -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 = {}
Expand Down
1 change: 1 addition & 0 deletions lib/socket.js
Expand Up @@ -14,6 +14,7 @@ function Socket(options) {
EventEmitter.apply(this)

if (options.proto === 'https') {
// https://github.com/nock/nock/issues/158
this.authorized = true
}

Expand Down
1 change: 1 addition & 0 deletions tests/test_intercept.js
Expand Up @@ -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')
Expand Down