MCPcopy Index your code
hub / github.com/nodejs/node / ClientRequest

Function ClientRequest

lib/_http_client.js:192–461  ·  view source on GitHub ↗
(input, options, cb)

Source from the content-addressed store, hash-verified

190};
191
192function 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);

Callers

nothing calls this directly

Calls 15

urlToHttpOptionsFunction · 0.85
ObjectAssignFunction · 0.85
StringClass · 0.85
validateHostFunction · 0.85
getTimerDurationFunction · 0.85
checkIsHttpTokenFunction · 0.85
rewriteForProxiedHttpFunction · 0.85
parseUniqueHeadersOptionFunction · 0.85
emitErrorEventFunction · 0.85
setHeaderMethod · 0.80
getHeaderMethod · 0.80
includesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…