According to the spec
If an import ends with `using headers` , resolve the `headers` import and use the resolved expression as additional headers supplied to the HTTP request.
It gives the example of
For example, if normalizedRequestHeaders in the above judgment was:
[ { mapKey = "Authorization", mapValue = "token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4" }
]
... then the HTTPS request for https://authority directory file would include the following header line:
Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4
However, it doesnβt seem to enumerate what expressions are considered valid to be used as HTTP headers. Some digging around in the Haskell code led me to this:
-- | Given a well-typed (of type `List { header : Text, value Text }` or
-- `List { mapKey : Text, mapValue Text }`) headers expressions in normal form
-- construct the corresponding binary http headers; otherwise return the empty
-- list.
toHeaders :: Expr s a -> [HTTPHeader]
toHeaders (ListLit _ hs) = Data.Foldable.toList (Data.Foldable.fold maybeHeaders)
where
maybeHeaders = mapM toHeader hs
toHeaders _ = []
toHeader :: Expr s a -> Maybe HTTPHeader
toHeader (RecordLit m) = do
TextLit (Chunks [] keyText ) <-
Dhall.Map.lookup "header" m <|> Dhall.Map.lookup "mapKey" m
TextLit (Chunks [] valueText) <-
Dhall.Map.lookup "value" m <|> Dhall.Map.lookup "mapValue" m
let keyBytes = Data.Text.Encoding.encodeUtf8 keyText
let valueBytes = Data.Text.Encoding.encodeUtf8 valueText
return (Data.CaseInsensitive.mk keyBytes, valueBytes)
toHeader _ = do
empty
This should surely be documented in the spec? (Or else it is and I havenβt found it!)
Happy to put together a PR to update the spec with what is documented in the Haskell code if necessary!