diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/world/net/http/header.lux | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/stdlib/source/library/lux/world/net/http/header.lux b/stdlib/source/library/lux/world/net/http/header.lux index 81c801924..9c8a75ff0 100644 --- a/stdlib/source/library/lux/world/net/http/header.lux +++ b/stdlib/source/library/lux/world/net/http/header.lux @@ -6,26 +6,25 @@ ["[0]" try (.only Try)] ["[0]" exception (.only Exception)]] [data - [text + ["[0]" text (.only) ["%" \\format]] [collection - ["[0]" dictionary]]] + ["[0]" list (.use "[1]#[0]" mix)] + ["[0]" dictionary (.only Dictionary)]]] [math [number - ["[0]" nat]]] - [world - ["[0]" environment - ["[1]" \\parser (.only Environment)]]]]] + ["[0]" nat]]]]] [// ["[0]" mime (.only MIME)] + ["[0]" cookie] [// (.only URL)]]) (type .public Headers - Environment) + (Dictionary Text Text)) (def .public empty Headers - environment.empty) + (dictionary.empty text.hash)) ... https://developer.mozilla.org/en-US/docs/Glossary/HTTP_header (type .public (Header of) @@ -50,6 +49,8 @@ {.#None} (exception.except ..unknown [(the #name header)]))) +(def separator ",") + (def .public (has header value) (All (_ of) (-> (Header of) of Headers @@ -60,7 +61,7 @@ ((the #in header) value) previous - (%.format previous "," ((the #in header) value)))))) + (%.format previous ..separator ((the #in header) value)))))) (def .public content_length (Header Nat) @@ -79,3 +80,25 @@ [#name "Location" #in (|>>) #out (|>> {try.#Success})]) + +(def assignment "=") + +(def .public set_cookies + (Header cookie.Jar) + [#name "Set-Cookie" + #in (|>> dictionary.entries + (list#mix (function (_ [name value] previous) + (when previous + "" (%.format name ..assignment value) + _ (%.format previous ..separator name ..assignment value))) + "")) + #out (|>> (text.all_split_by ..separator) + (list#mix (function (_ cookie jar) + (when (text.split_by ..assignment cookie) + {.#Some [name value]} + (dictionary.has name value jar) + + {.#None} + jar)) + cookie.empty) + {try.#Success})]) |