@@ -19,16 +19,18 @@ module Node.HTTP.Client
19
19
, setTimeout
20
20
, httpVersion
21
21
, responseHeaders
22
+ , responseCookies
22
23
, statusCode
23
24
, statusMessage
24
25
) where
25
26
26
- import Prelude (Unit , (<<<))
27
+ import Prelude (Unit , (<<<), ($) )
27
28
28
29
import Control.Monad.Eff (Eff )
30
+ import Data.Maybe (Maybe )
29
31
import Data.Foreign (Foreign , toForeign )
30
32
import Data.Options (Options , Option , options , opt )
31
- import Data.StrMap (StrMap ())
33
+ import Data.StrMap (StrMap (), delete , lookup )
32
34
import Node.HTTP (HTTP ())
33
35
import Node.Stream (Readable , Writable )
34
36
import Node.URL as URL
@@ -99,9 +101,17 @@ foreign import setTimeout :: forall eff. Request -> Int -> Eff (http :: HTTP | e
99
101
httpVersion :: Response -> String
100
102
httpVersion = _.httpVersion <<< unsafeCoerce
101
103
104
+ headers' :: forall a . Response -> StrMap a
105
+ headers' = _.headers <<< unsafeCoerce
106
+
102
107
-- | Get the response headers as a hash
108
+ -- | Cookies are not included and could be retrieved with responseCookies
103
109
responseHeaders :: 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
105
115
106
116
-- | Get the response status code
107
117
statusCode :: Response -> Int
0 commit comments