@@ -5,13 +5,15 @@ module Node.HTTP.Client
5
5
, Response ()
6
6
, RequestHeaders (..)
7
7
, RequestOptions ()
8
+ , RequestFamily (..)
8
9
, protocol
9
10
, hostname
10
11
, port
11
12
, method
12
13
, path
13
14
, headers
14
15
, auth
16
+ , family
15
17
, request
16
18
, requestFromURI
17
19
, requestAsStream
@@ -31,6 +33,7 @@ import Data.Maybe (Maybe)
31
33
import Data.Foreign (Foreign , toForeign )
32
34
import Data.Options (Options , Option , options , opt )
33
35
import Data.StrMap (StrMap (), delete , lookup )
36
+ import Data.Functor.Contravariant ((>$<))
34
37
import Node.HTTP (HTTP ())
35
38
import Node.Stream (Readable , Writable )
36
39
import Node.URL as URL
@@ -48,6 +51,9 @@ newtype RequestHeaders = RequestHeaders (StrMap String)
48
51
-- | The type of HTTP request options
49
52
data RequestOptions
50
53
54
+ -- | Values for the `family` request option
55
+ data RequestFamily = IPV4 | IPV6
56
+
51
57
-- | The protocol to use
52
58
protocol :: Option RequestOptions String
53
59
protocol = opt " protocol"
@@ -75,6 +81,16 @@ headers = opt "headers"
75
81
auth :: Option RequestOptions String
76
82
auth = opt " auth"
77
83
84
+ -- | IP address family to use when resolving `hostname`.
85
+ -- | Valid values are `IPV6` and `IPV4`
86
+ family :: Option RequestOptions RequestFamily
87
+ family = familyToOption >$< opt " family"
88
+
89
+ -- | Translates RequestFamily values to Int parameters for Request
90
+ familyToOption :: RequestFamily -> Int
91
+ familyToOption IPV4 = 4
92
+ familyToOption IPV6 = 6
93
+
78
94
-- | Make a HTTP request using the specified options and response callback.
79
95
foreign import requestImpl :: forall eff . Foreign -> (Response -> Eff (http :: HTTP | eff ) Unit ) -> Eff (http :: HTTP | eff ) Request
80
96
0 commit comments