| 76 | const NULL_BYTE_BUFFER = Buffer.from([NULL_BYTE]); |
| 77 | |
| 78 | export default class HttpStore<T> { |
| 79 | static HttpError: typeof HttpError = HttpError; |
| 80 | static NetworkError: typeof NetworkError = NetworkError; |
| 81 | |
| 82 | #getEndpoint: Endpoint; |
| 83 | #setEndpoint: Endpoint; |
| 84 | |
| 85 | constructor(options: Options) { |
| 86 | this.#getEndpoint = this.#createEndpointConfig( |
| 87 | options.getOptions != null ? options.getOptions : options, |
| 88 | ); |
| 89 | this.#setEndpoint = this.#createEndpointConfig( |
| 90 | options.setOptions != null ? options.setOptions : options, |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | #createEndpointConfig(options: EndpointOptions): Endpoint { |
| 95 | const agentConfig: http$agentOptions & HttpsProxyAgentOptions = { |
| 96 | family: options.family, |
| 97 | keepAlive: true, |
| 98 | keepAliveMsecs: options.timeout || 5000, |
| 99 | maxFreeSockets: 64, |
| 100 | maxSockets: 64, |
| 101 | }; |
| 102 | |
| 103 | if (options.key != null) { |
| 104 | // $FlowFixMe[incompatible-use] `key` is missing in the Flow definition |
| 105 | agentConfig.key = options.key; |
| 106 | } |
| 107 | |
| 108 | if (options.cert != null) { |
| 109 | // $FlowFixMe[incompatible-use] `cert` is missing in the Flow definition |
| 110 | agentConfig.cert = options.cert; |
| 111 | } |
| 112 | |
| 113 | if (options.ca != null) { |
| 114 | // $FlowFixMe[incompatible-use] `ca` is missing in the Flow definition |
| 115 | agentConfig.ca = options.ca; |
| 116 | } |
| 117 | |
| 118 | if (options.socketPath != null) { |
| 119 | // $FlowFixMe[incompatible-use] `socketPath` is missing in the Flow definition |
| 120 | agentConfig.socketPath = options.socketPath; |
| 121 | } |
| 122 | |
| 123 | const uri = new URL(options.endpoint); |
| 124 | const module = uri.protocol === 'http:' ? http : https; |
| 125 | |
| 126 | const agent = |
| 127 | options.proxy != null |
| 128 | ? new HttpsProxyAgent(options.proxy, agentConfig) |
| 129 | : new module.Agent(agentConfig); |
| 130 | |
| 131 | if (!uri.hostname || !uri.pathname) { |
| 132 | throw new TypeError('Invalid endpoint: ' + options.endpoint); |
| 133 | } |
| 134 | |
| 135 | return { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…