Files
codeql-action/node_modules/nock/lib/socket.js
dependabot[bot] 1d83e52e9a Bump the npm group with 5 updates (#1951)
* Bump the npm group with 5 updates

Bumps the npm group with 5 updates:

| Package | From | To |
| --- | --- | --- |
| [@types/js-yaml](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/js-yaml) | `4.0.6` | `4.0.7` |
| [@types/sinon](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/sinon) | `10.0.17` | `10.0.19` |
| [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) | `6.7.5` | `6.8.0` |
| [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) | `6.7.5` | `6.8.0` |
| [nock](https://github.com/nock/nock) | `13.3.3` | `13.3.4` |


Updates `@types/js-yaml` from 4.0.6 to 4.0.7
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/js-yaml)

Updates `@types/sinon` from 10.0.17 to 10.0.19
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/sinon)

Updates `@typescript-eslint/eslint-plugin` from 6.7.5 to 6.8.0
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.8.0/packages/eslint-plugin)

Updates `@typescript-eslint/parser` from 6.7.5 to 6.8.0
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.8.0/packages/parser)

Updates `nock` from 13.3.3 to 13.3.4
- [Release notes](https://github.com/nock/nock/releases)
- [Changelog](https://github.com/nock/nock/blob/main/CHANGELOG.md)
- [Commits](https://github.com/nock/nock/compare/v13.3.3...v13.3.4)

---
updated-dependencies:
- dependency-name: "@types/js-yaml"
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: "@types/sinon"
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: nock
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update checked-in dependencies

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-10-17 19:41:41 +00:00

109 lines
2.6 KiB
JavaScript

'use strict'
const { EventEmitter } = require('events')
const debug = require('debug')('nock.socket')
module.exports = class Socket extends EventEmitter {
constructor(options) {
super()
// Pretend this is a TLSSocket
if (options.proto === 'https') {
// https://github.com/nock/nock/issues/158
this.authorized = true
// https://github.com/nock/nock/issues/2147
this.encrypted = true
}
this.bufferSize = 0
this.writableLength = 0
this.writable = true
this.readable = true
this.pending = false
this.destroyed = false
this.connecting = true
// Undocumented flag used by ClientRequest to ensure errors aren't double-fired
this._hadError = false
// Maximum allowed delay. 0 means unlimited.
this.timeout = 0
const ipv6 = options.family === 6
this.remoteFamily = ipv6 ? 'IPv6' : 'IPv4'
this.localAddress = this.remoteAddress = ipv6 ? '::1' : '127.0.0.1'
this.localPort = this.remotePort = parseInt(options.port)
}
setNoDelay() {}
setKeepAlive() {}
resume() {}
ref() {}
unref() {}
write() {}
address() {
return {
port: this.remotePort,
family: this.remoteFamily,
address: this.remoteAddress,
}
}
setTimeout(timeoutMs, fn) {
this.timeout = timeoutMs
if (fn) {
this.once('timeout', fn)
}
return this
}
/**
* Artificial delay that will trip socket timeouts when appropriate.
*
* Doesn't actually wait for time to pass.
* Timeout events don't necessarily end the request.
* While many clients choose to abort the request upon a timeout, Node itself does not.
*/
applyDelay(delayMs) {
if (this.timeout && delayMs > this.timeout) {
debug('socket timeout')
this.emit('timeout')
}
}
getPeerCertificate() {
return Buffer.from(
(Math.random() * 10000 + Date.now()).toString(),
).toString('base64')
}
/**
* Denotes that no more I/O activity should happen on this socket.
*
* The implementation in Node if far more complex as it juggles underlying async streams.
* For the purposes of Nock, we just need it to set some flags and on the first call
* emit a 'close' and optional 'error' event. Both events propagate through the request object.
*/
destroy(err) {
if (this.destroyed) {
return this
}
debug('socket destroy')
this.destroyed = true
this.readable = this.writable = false
this.readableEnded = this.writableFinished = true
process.nextTick(() => {
if (err) {
this._hadError = true
this.emit('error', err)
}
this.emit('close')
})
return this
}
}