Skip to content

Added family request option to control IP address family #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/Node/HTTP/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ data RequestOptions

The type of HTTP request options

#### `RequestFamily`

``` purescript
data RequestFamily
= IPV4
| IPV6
```

Values for the `family` request option

#### `protocol`

``` purescript
Expand Down Expand Up @@ -89,6 +99,15 @@ auth :: Option RequestOptions String

Basic authentication

#### `family`

``` purescript
family :: Option RequestOptions RequestFamily
```

IP address family to use when resolving `hostname`.
Valid values are `IPV6` and `IPV4`

#### `request`

``` purescript
Expand Down Expand Up @@ -144,6 +163,15 @@ responseHeaders :: Response -> StrMap String
```

Get the response headers as a hash
Cookies are not included and could be retrieved with responseCookies

#### `responseCookies`

``` purescript
responseCookies :: Response -> Maybe (Array String)
```

Get the response cookies as Just (Array String) or Nothing if no cookies

#### `statusCode`

Expand Down
16 changes: 16 additions & 0 deletions src/Node/HTTP/Client.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ module Node.HTTP.Client
, Response()
, RequestHeaders(..)
, RequestOptions()
, RequestFamily(..)
, protocol
, hostname
, port
, method
, path
, headers
, auth
, family
, request
, requestFromURI
, requestAsStream
Expand All @@ -31,6 +33,7 @@ import Data.Maybe (Maybe)
import Data.Foreign (Foreign, toForeign)
import Data.Options (Options, Option, options, opt)
import Data.StrMap (StrMap(), delete, lookup)
import Data.Functor.Contravariant ((>$<))
import Node.HTTP (HTTP())
import Node.Stream (Readable, Writable)
import Node.URL as URL
Expand All @@ -48,6 +51,9 @@ newtype RequestHeaders = RequestHeaders (StrMap String)
-- | The type of HTTP request options
data RequestOptions

-- | Values for the `family` request option
data RequestFamily = IPV4 | IPV6

-- | The protocol to use
protocol :: Option RequestOptions String
protocol = opt "protocol"
Expand Down Expand Up @@ -75,6 +81,16 @@ headers = opt "headers"
auth :: Option RequestOptions String
auth = opt "auth"

-- | IP address family to use when resolving `hostname`.
-- | Valid values are `IPV6` and `IPV4`
family :: Option RequestOptions RequestFamily
family = familyToOption >$< opt "family"

-- | Translates RequestFamily values to Int parameters for Request
familyToOption :: RequestFamily -> Int
familyToOption IPV4 = 4
familyToOption IPV6 = 6

-- | Make a HTTP request using the specified options and response callback.
foreign import requestImpl :: forall eff. Foreign -> (Response -> Eff (http :: HTTP | eff) Unit) -> Eff (http :: HTTP | eff) Request

Expand Down