Skip to content

Commit a84947f

Browse files
committed
perf(router): use leaner security header lookups
Use null-returning Headers.get checks instead of Headers.has before applying defaults, preserving empty and custom caller values.\n\nA 500k-iteration median improved the default triad from 609 ns to 562 ns. In the live profile, native has self-time dropped from 6.6% to 0.3% while combined has/get lookup share fell from 10.4% to 7.5%. The shared-machine HTTP total was noisy and is not used as evidence.\n\nValidated with security and hot-path tests, framework type checks, and pickier lint.
1 parent 7ce922c commit a84947f

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

storage/framework/core/router/src/security-headers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ export function applySecurityHeaders(headers: Headers): void {
8282
if (isDisabled())
8383
return
8484

85-
if (!headers.has('X-Content-Type-Options'))
85+
if (headers.get('X-Content-Type-Options') === null)
8686
headers.set('X-Content-Type-Options', 'nosniff')
8787

88-
if (!headers.has('X-Frame-Options'))
88+
if (headers.get('X-Frame-Options') === null)
8989
headers.set('X-Frame-Options', 'SAMEORIGIN')
9090

91-
if (!headers.has('Referrer-Policy'))
91+
if (headers.get('Referrer-Policy') === null)
9292
headers.set('Referrer-Policy', 'strict-origin-when-cross-origin')
9393

94-
if (isProduction() && !headers.has('Strict-Transport-Security'))
94+
if (isProduction() && headers.get('Strict-Transport-Security') === null)
9595
headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains')
9696

9797
const csp = resolveCsp()
98-
if (csp && !headers.has(csp.header))
98+
if (csp && headers.get(csp.header) === null)
9999
headers.set(csp.header, csp.value)
100100
}
101101

0 commit comments

Comments
 (0)