Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch(HeadersList): s/has/contains #1775

Merged
merged 1 commit into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/fetch/headers.js
Expand Up @@ -142,11 +142,6 @@ class HeadersList {
return this[kHeadersMap].get(name) ?? null
}

has (name) {
name = name.toLowerCase()
return this[kHeadersMap].has(name)
}

* [Symbol.iterator] () {
for (const pair of this[kHeadersMap]) {
yield pair
Expand Down
30 changes: 15 additions & 15 deletions lib/fetch/index.js
Expand Up @@ -475,7 +475,7 @@ function fetching ({
}

// 12. If request’s header list does not contain `Accept`, then:
if (!request.headersList.has('accept')) {
if (!request.headersList.contains('accept')) {
// 1. Let value be `*/*`.
const value = '*/*'

Expand All @@ -498,7 +498,7 @@ function fetching ({
// 13. If request’s header list does not contain `Accept-Language`, then
// user agents should append `Accept-Language`/an appropriate value to
// request’s header list.
if (!request.headersList.has('accept-language')) {
if (!request.headersList.contains('accept-language')) {
request.headersList.append('accept-language', '*')
}

Expand Down Expand Up @@ -721,7 +721,7 @@ async function mainFetch (fetchParams, recursive = false) {
response.type === 'opaque' &&
internalResponse.status === 206 &&
internalResponse.rangeRequested &&
!request.headers.has('range')
!request.headers.contains('range')
) {
response = internalResponse = makeNetworkError()
}
Expand Down Expand Up @@ -1336,7 +1336,7 @@ async function httpNetworkOrCacheFetch (
// 14. If httpRequest’s header list does not contain `User-Agent`, then
// user agents should append `User-Agent`/default `User-Agent` value to
// httpRequest’s header list.
if (!httpRequest.headersList.has('user-agent')) {
if (!httpRequest.headersList.contains('user-agent')) {
httpRequest.headersList.append('user-agent', 'undici')
}

Expand All @@ -1346,11 +1346,11 @@ async function httpNetworkOrCacheFetch (
// httpRequest’s cache mode to "no-store".
if (
httpRequest.cache === 'default' &&
(httpRequest.headersList.has('if-modified-since') ||
httpRequest.headersList.has('if-none-match') ||
httpRequest.headersList.has('if-unmodified-since') ||
httpRequest.headersList.has('if-match') ||
httpRequest.headersList.has('if-range'))
(httpRequest.headersList.contains('if-modified-since') ||
httpRequest.headersList.contains('if-none-match') ||
httpRequest.headersList.contains('if-unmodified-since') ||
httpRequest.headersList.contains('if-match') ||
httpRequest.headersList.contains('if-range'))
) {
httpRequest.cache = 'no-store'
}
Expand All @@ -1362,7 +1362,7 @@ async function httpNetworkOrCacheFetch (
if (
httpRequest.cache === 'no-cache' &&
!httpRequest.preventNoCacheCacheControlHeaderModification &&
!httpRequest.headersList.has('cache-control')
!httpRequest.headersList.contains('cache-control')
) {
httpRequest.headersList.append('cache-control', 'max-age=0')
}
Expand All @@ -1371,27 +1371,27 @@ async function httpNetworkOrCacheFetch (
if (httpRequest.cache === 'no-store' || httpRequest.cache === 'reload') {
// 1. If httpRequest’s header list does not contain `Pragma`, then append
// `Pragma`/`no-cache` to httpRequest’s header list.
if (!httpRequest.headersList.has('pragma')) {
if (!httpRequest.headersList.contains('pragma')) {
httpRequest.headersList.append('pragma', 'no-cache')
}

// 2. If httpRequest’s header list does not contain `Cache-Control`,
// then append `Cache-Control`/`no-cache` to httpRequest’s header list.
if (!httpRequest.headersList.has('cache-control')) {
if (!httpRequest.headersList.contains('cache-control')) {
httpRequest.headersList.append('cache-control', 'no-cache')
}
}

// 18. If httpRequest’s header list contains `Range`, then append
// `Accept-Encoding`/`identity` to httpRequest’s header list.
if (httpRequest.headersList.has('range')) {
if (httpRequest.headersList.contains('range')) {
httpRequest.headersList.append('accept-encoding', 'identity')
}

// 19. Modify httpRequest’s header list per HTTP. Do not append a given
// header if httpRequest’s header list contains that header’s name.
// TODO: https://github.com/whatwg/fetch/issues/1285#issuecomment-896560129
if (!httpRequest.headersList.has('accept-encoding')) {
if (!httpRequest.headersList.contains('accept-encoding')) {
if (/^https:/.test(requestCurrentURL(httpRequest).protocol)) {
httpRequest.headersList.append('accept-encoding', 'br, gzip, deflate')
} else {
Expand Down Expand Up @@ -1480,7 +1480,7 @@ async function httpNetworkOrCacheFetch (

// 12. If httpRequest’s header list contains `Range`, then set response’s
// range-requested flag.
if (httpRequest.headersList.has('range')) {
if (httpRequest.headersList.contains('range')) {
response.rangeRequested = true
}

Expand Down
2 changes: 1 addition & 1 deletion lib/fetch/response.js
Expand Up @@ -487,7 +487,7 @@ function initializeResponse (response, init, body) {

// 3. If body's type is non-null and response's header list does not contain
// `Content-Type`, then append (`Content-Type`, body's type) to response's header list.
if (body.type != null && !response[kState].headersList.has('Content-Type')) {
if (body.type != null && !response[kState].headersList.contains('Content-Type')) {
response[kState].headersList.append('content-type', body.type)
}
}
Expand Down