Skip to content

Commit 0a1683b

Browse files
authored
Merge pull request #9 from kika/master
Added family request option to control IP address family
2 parents f1d7a38 + 47a09ea commit 0a1683b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

docs/Node/HTTP/Client.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ data RequestOptions
3535

3636
The type of HTTP request options
3737

38+
#### `RequestFamily`
39+
40+
``` purescript
41+
data RequestFamily
42+
= IPV4
43+
| IPV6
44+
```
45+
46+
Values for the `family` request option
47+
3848
#### `protocol`
3949

4050
``` purescript
@@ -89,6 +99,15 @@ auth :: Option RequestOptions String
8999

90100
Basic authentication
91101

102+
#### `family`
103+
104+
``` purescript
105+
family :: Option RequestOptions RequestFamily
106+
```
107+
108+
IP address family to use when resolving `hostname`.
109+
Valid values are `IPV6` and `IPV4`
110+
92111
#### `request`
93112

94113
``` purescript
@@ -144,6 +163,15 @@ responseHeaders :: Response -> StrMap String
144163
```
145164

146165
Get the response headers as a hash
166+
Cookies are not included and could be retrieved with responseCookies
167+
168+
#### `responseCookies`
169+
170+
``` purescript
171+
responseCookies :: Response -> Maybe (Array String)
172+
```
173+
174+
Get the response cookies as Just (Array String) or Nothing if no cookies
147175

148176
#### `statusCode`
149177

src/Node/HTTP/Client.purs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ module Node.HTTP.Client
55
, Response()
66
, RequestHeaders(..)
77
, RequestOptions()
8+
, RequestFamily(..)
89
, protocol
910
, hostname
1011
, port
1112
, method
1213
, path
1314
, headers
1415
, auth
16+
, family
1517
, request
1618
, requestFromURI
1719
, requestAsStream
@@ -31,6 +33,7 @@ import Data.Maybe (Maybe)
3133
import Data.Foreign (Foreign, toForeign)
3234
import Data.Options (Options, Option, options, opt)
3335
import Data.StrMap (StrMap(), delete, lookup)
36+
import Data.Functor.Contravariant ((>$<))
3437
import Node.HTTP (HTTP())
3538
import Node.Stream (Readable, Writable)
3639
import Node.URL as URL
@@ -48,6 +51,9 @@ newtype RequestHeaders = RequestHeaders (StrMap String)
4851
-- | The type of HTTP request options
4952
data RequestOptions
5053

54+
-- | Values for the `family` request option
55+
data RequestFamily = IPV4 | IPV6
56+
5157
-- | The protocol to use
5258
protocol :: Option RequestOptions String
5359
protocol = opt "protocol"
@@ -75,6 +81,16 @@ headers = opt "headers"
7581
auth :: Option RequestOptions String
7682
auth = opt "auth"
7783

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+
7894
-- | Make a HTTP request using the specified options and response callback.
7995
foreign import requestImpl :: forall eff. Foreign -> (Response -> Eff (http :: HTTP | eff) Unit) -> Eff (http :: HTTP | eff) Request
8096

0 commit comments

Comments
 (0)