MCPcopy Create free account
hub / github.com/nodejs/node / constructor

Method constructor

deps/undici/src/lib/web/fetch/request.js:108–599  ·  view source on GitHub ↗
(input, init = undefined)

Source from the content-addressed store, hash-verified

106
107 // https://fetch.spec.whatwg.org/#dom-request
108 constructor (input, init = undefined) {
109 webidl.util.markAsUncloneable(this)
110
111 if (input === kConstruct) {
112 return
113 }
114
115 const prefix = 'Request constructor'
116 webidl.argumentLengthCheck(arguments, 1, prefix)
117
118 input = webidl.converters.RequestInfo(input)
119 init = webidl.converters.RequestInit(init)
120
121 // 1. Let request be null.
122 let request = null
123
124 // 2. Let fallbackMode be null.
125 let fallbackMode = null
126
127 // 3. Let baseURL be this’s relevant settings object’s API base URL.
128 const baseUrl = environmentSettingsObject.settingsObject.baseUrl
129
130 // 4. Let signal be null.
131 let signal = null
132
133 // 5. If input is a string, then:
134 if (typeof input === 'string') {
135 this.#dispatcher = init.dispatcher
136
137 // 1. Let parsedURL be the result of parsing input with baseURL.
138 // 2. If parsedURL is failure, then throw a TypeError.
139 let parsedURL
140 try {
141 parsedURL = new URL(input, baseUrl)
142 } catch (err) {
143 throw new TypeError('Failed to parse URL from ' + input, { cause: err })
144 }
145
146 // 3. If parsedURL includes credentials, then throw a TypeError.
147 if (parsedURL.username || parsedURL.password) {
148 throw new TypeError(
149 'Request cannot be constructed from a URL that includes credentials: ' +
150 input
151 )
152 }
153
154 // 4. Set request to a new request whose URL is parsedURL.
155 request = makeRequest({ urlList: [parsedURL] })
156
157 // 5. Set fallbackMode to "cors".
158 fallbackMode = 'cors'
159 } else {
160 // 6. Otherwise:
161
162 // 7. Assert: input is a Request object.
163 assert(webidl.is.Request(input))
164
165 // 8. Set request to input’s request.

Callers

nothing calls this directly

Calls 15

abortMethod · 0.95
StringClass · 0.85
getMaxListenersFunction · 0.85
fillHeadersFunction · 0.85
markAsUncloneableMethod · 0.80
argumentLengthCheckMethod · 0.80
RequestInfoMethod · 0.80
RequestInitMethod · 0.80
exceptionMethod · 0.80
pipeThroughMethod · 0.80
makeRequestFunction · 0.70
sameOriginFunction · 0.70

Tested by

no test coverage detected