Skip to content

Commit

Permalink
perf: optimize HeadersList.get (nodejs#2420)
Browse files Browse the repository at this point in the history
* perf: optimize HeadersList.get

* simple
  • Loading branch information
tsctx authored and crysmags committed Feb 27, 2024
1 parent 912eee2 commit add731b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,13 @@ class HeadersList {

// https://fetch.spec.whatwg.org/#concept-header-list-get
get (name) {
// 1. If list does not contain name, then return null.
if (!this.contains(name)) {
return null
}
const value = this[kHeadersMap].get(name.toLowerCase())

// 1. If list does not contain name, then return null.
// 2. Return the values of all headers in list whose name
// is a byte-case-insensitive match for name,
// separated from each other by 0x2C 0x20, in order.
return this[kHeadersMap].get(name.toLowerCase())?.value ?? null
return value === undefined ? null : value.value
}

* [Symbol.iterator] () {
Expand Down

0 comments on commit add731b

Please sign in to comment.