(input, options, cb)
| 190 | }; |
| 191 | |
| 192 | function ClientRequest(input, options, cb) { |
| 193 | OutgoingMessage.call(this); |
| 194 | |
| 195 | if (typeof input === 'string') { |
| 196 | const urlStr = input; |
| 197 | input = urlToHttpOptions(new URL(urlStr)); |
| 198 | } else if (isURL(input)) { |
| 199 | // url.URL instance |
| 200 | input = urlToHttpOptions(input); |
| 201 | } else { |
| 202 | cb = options; |
| 203 | options = input; |
| 204 | input = null; |
| 205 | } |
| 206 | |
| 207 | if (typeof options === 'function') { |
| 208 | cb = options; |
| 209 | options = input || kEmptyObject; |
| 210 | } else { |
| 211 | options = ObjectAssign({ __proto__: null }, input, options); |
| 212 | } |
| 213 | |
| 214 | let agent = options.agent; |
| 215 | const defaultAgent = options._defaultAgent || Agent.globalAgent; |
| 216 | if (agent === false) { |
| 217 | agent = new defaultAgent.constructor(); |
| 218 | } else if (agent === null || agent === undefined) { |
| 219 | if (typeof options.createConnection !== 'function') { |
| 220 | agent = defaultAgent; |
| 221 | } |
| 222 | // Explicitly pass through this statement as agent will not be used |
| 223 | // when createConnection is provided. |
| 224 | } else if (typeof agent.addRequest !== 'function') { |
| 225 | throw new ERR_INVALID_ARG_TYPE('options.agent', |
| 226 | ['Agent-like Object', 'undefined', 'false'], |
| 227 | agent); |
| 228 | } |
| 229 | this.agent = agent; |
| 230 | |
| 231 | const protocol = options.protocol || defaultAgent.protocol; |
| 232 | let expectedProtocol = defaultAgent.protocol; |
| 233 | if (this.agent?.protocol) |
| 234 | expectedProtocol = this.agent.protocol; |
| 235 | |
| 236 | if (options.path) { |
| 237 | const path = String(options.path); |
| 238 | if (INVALID_PATH_REGEX.test(path)) { |
| 239 | debug('Path contains unescaped characters: "%s"', path); |
| 240 | throw new ERR_UNESCAPED_CHARACTERS('Request path'); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | if (protocol !== expectedProtocol) { |
| 245 | throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol); |
| 246 | } |
| 247 | |
| 248 | const defaultPort = options.defaultPort || |
| 249 | (this.agent?.defaultPort); |
nothing calls this directly
no test coverage detected
searching dependent graphs…