http/header_lines.ts

A request header as the lines the client sent — one field value per header line, in order — where the Fetch Headers a handler normally reads has already folded them into one string.

The credential readers (auth/credential_headers.ts) and the gate readers (http/request_headers.ts) decide on the lines: a credential header sent twice is discarded, an Origin or Host sent twice is refused, and that takes knowing it was sent twice. Headers.get joins repeated lines with , , and @hono/node-server builds a WebSocket upgrade's Headers from Node's deduplicated view, which keeps only the first Authorization, Host, Referer or Content-Type line and drops every empty one — so on that path neither the join nor an empty line shows.

view source

Declarations
#

2 declarations

get_header_lines
#

http/header_lines.ts view source

(c: Context<any, any, {}>, name: string): string[] import {get_header_lines} from '@fuzdev/fuz_app/http/header_lines.js';

Read one request header as the lines it was sent in.

On @hono/node-server the lines come from the request's raw header list (c.env.incoming.rawHeaders), so a header sent twice is two entries. A runtime with no per-line view — Bun, and an in-process app.request — gives the Fetch Headers value as the single line: repeated lines arrive already joined (; for Cookie, , otherwise), and a caller that must tell a repeat from one line reads a grammar that refuses the join.

c

the request context

type Context<any, any, {}>

name

the header name, in any case

type string

returns

string[]

the header's field values, outer SP and HTAB stripped, in the order sent — [] when the request carries no such header

trim_optional_whitespace
#

http/header_lines.ts view source

(text: string): string import {trim_optional_whitespace} from '@fuzdev/fuz_app/http/header_lines.js';

Strip HTTP optional whitespace — SP and HTAB, nothing else — from both ends of a field value or a part of one. String.prototype.trim strips more: a header byte 0xA0 reaches a handler as U+00A0, which it counts as whitespace.

text

a field value, or a part of one

type string

returns

string

text without its leading and trailing SP and HTAB

Imported by
#