httpheaders
nimony/lib/std/http/httpheaders.nim
HttpHeaders: header lines in their HTTP/1.1 wire format, Name: value\r\n in order (nim-lang/nimony#2635).
Construction, iteration and case-insensitive lookup are available without importing a client. std/httpclient re-exports this module.
type HttpHeaders = distinct stringName: value\r\nlines, in order. Repeated names are just lines; lookup is a case-insensitive linear scan.func isTokenChar(c: char): boolRFC 9110
tchar: what a header name is made of.template headers(s: string): HttpHeadersA header block literal, checked while the program is compiled:
headers"Accept: application/json\r\n". A malformed block is a compile-time error. Values known only at run time go throughadd.proc add(h: var HttpHeaders; name: string; value: string)Appends
name: value.BadOperationfor a name outside the token characters or a CR/LF in the value.iterator pairs(h: HttpHeaders): tuple[string, string]Every name and value in wire order, preserving duplicate fields and name spelling. Values have surrounding whitespace removed.
iterator values(h: HttpHeaders; name: string): stringEvery value of
name, case-insensitively, in wire order.proc get(h: HttpHeaders; name: string): stringThe first value of
name, case-insensitively;""if absent.proc has(h: HttpHeaders; name: string): boolWhether
nameis present, case-insensitively, even if its value is empty.func spelledLineEnds(s: string): stringheaders"A: b\r\n"is a raw string literal: its\r\narrives spelled out, as four characters. Both spellings mean the line end.func headerBlockError(s: string): stringWhy
sis not a header block, or""when it is one: every linetoken: value\r\n, no stray CR or LF (an injected line), nothing after the last line end.func validHeaderBlock(s: string): bool