2 Head
(require (planet gh/http:1:=0/head)) |
2.1 Supplements to net/head
These stick with net/head’s respresentation of headers as a string?, and add a few functions that are "missing" or would be convenient.
procedure
(extract-http-ver h) → string?
h : string?
procedure
h : string?
procedure
(extract-http-text h) → string?
h : string?
procedure
(extract-field/number field h [radix]) → (or/c #f number?)
field : string? h : string? radix : exact-positive-integer? = 10
procedure
(maybe-insert-field field value h) → string?
field : (or/c symbol? string?) value : any/c h : string?
Use case: You want to ensure the header is present, but not disrupt any
existing value—
procedure
(coalesce-fields h) → string?
h : string?
Some web services (hello Amazon) require this as part of "signing" a request for authentication, which means it has to be done exactly right.
procedure
h : string?
2.2 Heads as a dict
procedure
(heads-string->dict s [dupe-sep]) → dict?
s : string? dupe-sep : string? = "\n"
Specifically, handle the case of duplicate headers. A real-world example of such duplicate headers is Set-Cookie. Other than association lists, most types of dicts don’t permit duplicate keys, so we can’t store duplicate headers using those. Instead, duplicate headers are stored in the dict under the same key, with the various values separated by dupe-sep.
Examples: | ||||
|
procedure
(heads-dict->string d) → string?
d : dict?
Examples: | ||||
|
procedure
(maybe-dict-set d k v) → (and/c dict? dict-can-functional-set?)
d : (and/c dict? dict-can-functional-set?) k : symbol? v : any/c
Examples: | ||||
|
procedure
(maybe-dict-set* d kvs) → (and/c dict? dict-can-functional-set?)
d : (and/c dict? dict-can-functional-set?) kvs : list?