Back to all reviewers

Use proper HTTP utilities

nuxt/nuxt
Based on 2 comments
Markdown

When handling HTTP cookies and headers, use dedicated utility functions instead of manual string manipulation. Manual parsing of HTTP headers, especially cookies, can lead to incorrect behavior due to the complexity of HTTP header formats.

Networking Markdown

Reviewer Prompt

When handling HTTP cookies and headers, use dedicated utility functions instead of manual string manipulation. Manual parsing of HTTP headers, especially cookies, can lead to incorrect behavior due to the complexity of HTTP header formats.

For cookie handling, prefer established utilities like splitCookiesString from h3 or native browser APIs like headers.getSetCookie() over manual string splitting:

// โŒ Avoid manual cookie parsing
const cookies = (res.headers.get('set-cookie') || '').split(',')

// โœ… Use proper utilities
import { splitCookiesString } from 'h3'
const cookies = splitCookiesString(res.headers.get('set-cookie') || '')

// โœ… Or use native browser API
const cookies = res.headers.getSetCookie()

This approach ensures correct parsing of complex cookie values that may contain commas, semicolons, or other special characters that would break simple string splitting. Always verify that utility functions are available in your target environment before using them.

2
Comments Analyzed
Markdown
Primary Language
Networking
Category

Source Discussions