aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/world/net/http/header.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/world/net/http/header.lux')
-rw-r--r--stdlib/source/library/lux/world/net/http/header.lux78
1 files changed, 62 insertions, 16 deletions
diff --git a/stdlib/source/library/lux/world/net/http/header.lux b/stdlib/source/library/lux/world/net/http/header.lux
index 91ad629a2..81c801924 100644
--- a/stdlib/source/library/lux/world/net/http/header.lux
+++ b/stdlib/source/library/lux/world/net/http/header.lux
@@ -1,35 +1,81 @@
(.require
[library
- [lux (.except)
+ [lux (.except has)
[control
- ["[0]" pipe]]
+ ["[0]" pipe]
+ ["[0]" try (.only Try)]
+ ["[0]" exception (.only Exception)]]
[data
[text
- ["%" \\format (.only format)]]
+ ["%" \\format]]
[collection
- ["[0]" dictionary (.only Dictionary)]]]]]
- [// (.only Header)
+ ["[0]" dictionary]]]
+ [math
+ [number
+ ["[0]" nat]]]
+ [world
+ ["[0]" environment
+ ["[1]" \\parser (.only Environment)]]]]]
+ [//
["[0]" mime (.only MIME)]
[// (.only URL)]])
-(def .public (has name value)
- (-> Text Text Header)
- (dictionary.revised' name ""
+(type .public Headers
+ Environment)
+
+(def .public empty
+ Headers
+ environment.empty)
+
+... https://developer.mozilla.org/en-US/docs/Glossary/HTTP_header
+(type .public (Header of)
+ (Record
+ [#name Text
+ #in (-> of Text)
+ #out (-> Text (Try of))]))
+
+(exception.def .public (unknown [name])
+ (Exception Text)
+ (exception.report
+ (list ["Name" (%.text name)])))
+
+(def .public (one header it)
+ (All (_ of)
+ (-> (Header of) Headers
+ (Try of)))
+ (when (dictionary.value (the #name header) it)
+ {.#Some raw}
+ ((the #out header) raw)
+
+ {.#None}
+ (exception.except ..unknown [(the #name header)])))
+
+(def .public (has header value)
+ (All (_ of)
+ (-> (Header of) of Headers
+ Headers))
+ (dictionary.revised' (the #name header) ""
(|>> (pipe.when
""
- value
+ ((the #in header) value)
previous
- (format previous "," value)))))
+ (%.format previous "," ((the #in header) value))))))
(def .public content_length
- (-> Nat Header)
- (|>> %.nat (..has "Content-Length")))
+ (Header Nat)
+ [#name "Content-Length"
+ #in (at nat.decimal encoded)
+ #out (at nat.decimal decoded)])
(def .public content_type
- (-> MIME Header)
- (|>> mime.name (..has "Content-Type")))
+ (Header MIME)
+ [#name "Content-Type"
+ #in mime.name
+ #out (|>> mime.mime {try.#Success})])
(def .public location
- (-> URL Header)
- (..has "Location"))
+ (Header URL)
+ [#name "Location"
+ #in (|>>)
+ #out (|>> {try.#Success})])