Skip to content

Commit

Permalink
perf: use tree
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx committed Dec 20, 2023
1 parent 871baa7 commit 4098392
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ function parseRawHeaders (headers) {
let contentDispositionIdx = -1

for (let n = 0; n < headers.length; n += 2) {
const key = headers[n + 0].toString()
const key = headerNameToString(headers[n + 0])
const val = headers[n + 1].toString('utf8')

if (key.length === 14 && (key === 'content-length' || key.toLowerCase() === 'content-length')) {
if (key === 'content-length') {
ret.push(key, val)
hasContentLength = true
} else if (key.length === 19 && (key === 'content-disposition' || key.toLowerCase() === 'content-disposition')) {
} else if (key === 'content-disposition') {
contentDispositionIdx = ret.push(key, val) - 1
} else {
ret.push(key, val)
Expand Down
19 changes: 12 additions & 7 deletions lib/handler/RedirectHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,25 @@ function parseLocation (statusCode, headers) {
}

for (let i = 0; i < headers.length; i += 2) {
if (headers[i].toString().toLowerCase() === 'location') {
if (headers[i].length === 8 && util.headerNameToString(headers[i]) === 'location') {
return headers[i + 1]
}
}
}

// https://tools.ietf.org/html/rfc7231#section-6.4.4
function shouldRemoveHeader (header, removeContent, unknownOrigin) {
return (
(header.length === 4 && header.toString().toLowerCase() === 'host') ||
(removeContent && header.toString().toLowerCase().indexOf('content-') === 0) ||
(unknownOrigin && header.length === 13 && header.toString().toLowerCase() === 'authorization') ||
(unknownOrigin && header.length === 6 && header.toString().toLowerCase() === 'cookie')
)
if (header.length === 4) {
return util.headerNameToString(header) === 'host'
}
if (removeContent && util.headerNameToString(header).startsWith('content-')) {
return true
}
if (unknownOrigin && (header.length === 13 || header.length === 6)) {
const name = util.headerNameToString(header)
return name === 'authorization' || name === 'cookie'
}
return false
}

// https://tools.ietf.org/html/rfc7231#section-6.4
Expand Down

0 comments on commit 4098392

Please sign in to comment.