Back to all reviewers

Preserve HTTP header semantics

nuxt/nuxt
Based on 2 comments
TypeScript

HTTP headers have specific semantics that must be respected when processing, merging, or deduplicating them. Avoid naive approaches that treat headers as simple key-value pairs, as this can break protocol compliance and cause unexpected behavior.

Networking TypeScript

Reviewer Prompt

HTTP headers have specific semantics that must be respected when processing, merging, or deduplicating them. Avoid naive approaches that treat headers as simple key-value pairs, as this can break protocol compliance and cause unexpected behavior.

For set-cookie headers, remember that cookies are distinct by multiple attributes (name, domain, path, secure, httpOnly, sameSite), not just their values. Simple equality checks on cookie values can incorrectly deduplicate distinct cookies that should coexist.

When handling response headers, preserve existing headers rather than flattening them. Use appropriate header manipulation functions that understand header-specific rules:

// Good: Preserve header semantics
if (header === 'set-cookie') {
  appendResponseHeader(event, header, value)  // Preserves multiple set-cookie headers
} else {
  setResponseHeader(event, header, value)
}

// Bad: Naive deduplication that breaks cookie semantics  
if (isEqual(cookie.value, existingCookie.value)) { 
  return // This ignores domain, path, and other cookie attributes
}

Always use protocol-aware utilities and libraries that understand the specific rules for each header type, rather than implementing custom string manipulation logic.

2
Comments Analyzed
TypeScript
Primary Language
Networking
Category

Source Discussions