|(require (planet gh/http:1:=3/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.
field : string? h : string? radix : exact-positive-integer? = 10
Use case: You want to ensure the header is present, but not disrupt any
Some web services (hello Amazon) require this as part of "signing" a request for authentication, which means it has to be done exactly right.
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.
> (heads-string->dict "Host: Foo\r\nKey: Value\r\n\r\n") '#hash((Host . "Foo") (Key . "Value")) > (heads-string->dict "Key: Value 1\r\nKey: Value 2\r\n\r\n") '#hash((Key . "Value 1\nValue 2"))
> (heads-dict->string '#hash((Host . "Foo") (Key . "Value"))) "Host: Foo\r\nKey: Value\r\n\r\n" > (heads-dict->string '((Host . "Foo") (Key . "Value"))) "Host: Foo\r\nKey: Value\r\n\r\n"
d : (and/c dict? dict-can-functional-set?) k : symbol? v : any/c
> (maybe-dict-set '() 'a "New") '((a . "New")) > (maybe-dict-set '([a . "Old"]) 'a "New") '((a . "Old"))
d : (and/c dict? dict-can-functional-set?) kvs : list?