@@ -19,16 +19,18 @@ module Node.HTTP.Client
1919 , setTimeout
2020 , httpVersion
2121 , responseHeaders
22+ , responseCookies
2223 , statusCode
2324 , statusMessage
2425 ) where
2526
26- import Prelude (Unit , (<<<))
27+ import Prelude (Unit , (<<<), ($) )
2728
2829import Control.Monad.Eff (Eff )
30+ import Data.Maybe (Maybe )
2931import Data.Foreign (Foreign , toForeign )
3032import Data.Options (Options , Option , options , opt )
31- import Data.StrMap (StrMap ())
33+ import Data.StrMap (StrMap (), delete , lookup )
3234import Node.HTTP (HTTP ())
3335import Node.Stream (Readable , Writable )
3436import Node.URL as URL
@@ -99,9 +101,17 @@ foreign import setTimeout :: forall eff. Request -> Int -> Eff (http :: HTTP | e
99101httpVersion :: Response -> String
100102httpVersion = _.httpVersion <<< unsafeCoerce
101103
104+ headers' :: forall a . Response -> StrMap a
105+ headers' = _.headers <<< unsafeCoerce
106+
102107-- | Get the response headers as a hash
108+ -- | Cookies are not included and could be retrieved with responseCookies
103109responseHeaders :: Response -> StrMap String
104- responseHeaders = _.headers <<< unsafeCoerce
110+ responseHeaders res = delete " set-cookie" $ headers' res
111+
112+ -- | Get the response cookies as Just (Array String) or Nothing if no cookies
113+ responseCookies :: Response -> Maybe (Array String )
114+ responseCookies res = lookup " set-cookie" $ headers' res
105115
106116-- | Get the response status code
107117statusCode :: Response -> Int
0 commit comments