MCPcopy
hub / github.com/nodejs/undici / HeadersList

Class HeadersList

lib/web/fetch/headers.js:193–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193class HeadersList {
194 /** @type {[string, string][]|null} */
195 cookies = null
196
197 sortedMap
198 headersMap
199
200 constructor (init) {
201 if (init instanceof HeadersList) {
202 this.headersMap = new Map(init.headersMap)
203 this.sortedMap = init.sortedMap
204 this.cookies = init.cookies === null ? null : [...init.cookies]
205 } else {
206 this.headersMap = new Map(init)
207 this.sortedMap = null
208 }
209 }
210
211 /**
212 * @see https://fetch.spec.whatwg.org/#header-list-contains
213 * @param {string} name
214 * @param {boolean} isLowerCase
215 */
216 contains (name, isLowerCase) {
217 // A header list list contains a header name name if list
218 // contains a header whose name is a byte-case-insensitive
219 // match for name.
220
221 return this.headersMap.has(isLowerCase ? name : name.toLowerCase())
222 }
223
224 clear () {
225 this.headersMap.clear()
226 this.sortedMap = null
227 this.cookies = null
228 }
229
230 /**
231 * @see https://fetch.spec.whatwg.org/#concept-header-list-append
232 * @param {string} name
233 * @param {string} value
234 * @param {boolean} isLowerCase
235 */
236 append (name, value, isLowerCase) {
237 this.sortedMap = null
238
239 // 1. If list contains name, then set name to the first such
240 // header’s name.
241 const lowercaseName = isLowerCase ? name : name.toLowerCase()
242 const exists = this.headersMap.get(lowercaseName)
243
244 // 2. Append (name, value) to list.
245 if (exists) {
246 const delimiter = lowercaseName === 'cookie' ? '; ' : ', '
247 this.headersMap.set(lowercaseName, {
248 name: exists.name,
249 value: `${exists.value}${delimiter}${value}`
250 })

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…