Skip to content

Reimplement bindings #49

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 28 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2db7ca1
Add bindings to Incoming/OutgoingMessage
JordanMartinez Jul 29, 2023
4c8c880
add comments for which FFI is allowed
JordanMartinez Jul 29, 2023
3fbea8a
Use ty var to prevent incorrect usage
JordanMartinez Jul 29, 2023
aaa9180
Update exports
JordanMartinez Jul 29, 2023
f9674ac
Add bindings to ClientRequest & ServerResponse
JordanMartinez Jul 29, 2023
7da25fc
Add bindings to Server
JordanMartinez Jul 29, 2023
b94570c
Move current HTTP bindings to `old`
JordanMartinez Jul 29, 2023
b4c745b
Finish all but Agent for node:http bindings
JordanMartinez Jul 29, 2023
0d08fe3
Move Secure into old
JordanMartinez Jul 29, 2023
2230214
Fix FFI name
JordanMartinez Jul 29, 2023
c57994f
Implement bindings to `https`
JordanMartinez Jul 29, 2023
dd39a92
Remove old bindings
JordanMartinez Jul 29, 2023
b03db19
Fix FFI & export list for ClientRequest
JordanMartinez Jul 29, 2023
c1b6165
Update fn to match returned type
JordanMartinez Jul 29, 2023
46be9dd
Make things not effectful
JordanMartinez Jul 29, 2023
e51281e
Delineate between headers and cookies
JordanMartinez Jul 29, 2023
055a659
Add opts-only-arg version of request/get
JordanMartinez Jul 31, 2023
e2394d5
Add FFI: implicit set/get of status code/msg
JordanMartinez Jul 31, 2023
f15caa7
Drop duplicate API for https server
JordanMartinez Jul 31, 2023
9cc718b
Unify `http` and `https` server API
JordanMartinez Jul 31, 2023
2e57d01
Rename module to `Node.HTTPS`
JordanMartinez Jul 31, 2023
1afa9a8
Make tests compile and pass again
JordanMartinez Jul 31, 2023
bf0626c
Add docs
JordanMartinez Jul 31, 2023
e49ea49
Update url to 7.0.0
JordanMartinez Aug 1, 2023
35e7fca
Expose URL-variant of request/get
JordanMartinez Aug 1, 2023
13c4995
Update export lists: exclude FFI
JordanMartinez Aug 1, 2023
4dd5fc3
Add changelog entry
JordanMartinez Aug 1, 2023
08604f6
Update CI actions/node; add purs-tidy
JordanMartinez Aug 1, 2023
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
Prev Previous commit
Next Next commit
Expose URL-variant of request/get
  • Loading branch information
JordanMartinez committed Aug 1, 2023
commit 35e7fcaee1eb7e488905100239d53852d1fb1d3a
8 changes: 6 additions & 2 deletions src/Node/HTTP.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ export const createServerOptsImpl = (opts) => http.createServer(opts);

export const maxHeaderSize = http.maxHeaderSize;

export const requestImpl = (url) => http.request(url);
export const requestStrImpl = (url) => http.request(url);
export const requestStrOptsImpl = (url, opts) => http.request(url, opts);
export const requestUrlImpl = (url) => http.request(url);
export const requestUrlOptsImpl = (url, opts) => http.request(url, opts);
export const requestOptsImpl = (opts) => http.request(opts);

export const getImpl = (url) => http.get(url);
export const getStrImpl = (url) => http.get(url);
export const getStrOptsImpl = (url, opts) => http.get(url, opts);
export const getUrlImpl = (url) => http.get(url);
export const getUrlOptsImpl = (url, opts) => http.get(url, opts);
export const getOptsImpl = (opts) => http.get(opts);

Expand Down
56 changes: 44 additions & 12 deletions src/Node/HTTP.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foreign.Object (Object)
import Node.HTTP.Types (ClientRequest, HttpServer)
import Node.Net.Types (ConnectTcpOptions)
import Node.Stream (Duplex)
import Node.URL (URL)
import Prim.Row as Row

-- | - `connectionsCheckingInterval`: Sets the interval value in milliseconds to check for request and headers timeout in incomplete requests. Default: 30000.
Expand Down Expand Up @@ -47,9 +48,14 @@ foreign import createServerOptsImpl :: forall r. EffectFn1 ({ | r }) (HttpServer
foreign import maxHeaderSize :: Int

request :: String -> Effect ClientRequest
request url = runEffectFn1 requestImpl url
request url = runEffectFn1 requestStrImpl url

foreign import requestImpl :: EffectFn1 (String) (ClientRequest)
foreign import requestStrImpl :: EffectFn1 (String) (ClientRequest)

requestUrl :: URL -> Effect ClientRequest
requestUrl url = runEffectFn1 requestUrlImpl url

foreign import requestUrlImpl :: EffectFn1 (URL) (ClientRequest)

-- | - `auth` <string> Basic authentication ('user:password') to compute an Authorization header.
-- | - `createConnection` <Function> A function that produces a socket/stream to use for the request when the agent option is not used. This can be used to avoid creating a custom Agent class just to override the default createConnection function. See agent.createConnection() for more details. Any Duplex stream is a valid return value.
Expand Down Expand Up @@ -105,23 +111,38 @@ request'
=> String
-> { | r }
-> Effect ClientRequest
request' url opts = runEffectFn2 requestUrlOptsImpl url opts
request' url opts = runEffectFn2 requestStrOptsImpl url opts

foreign import requestUrlOptsImpl :: forall r. EffectFn2 (String) ({ | r }) (ClientRequest)
foreign import requestStrOptsImpl :: forall r. EffectFn2 (String) ({ | r }) (ClientRequest)

request''
requestURL'
:: forall r trash
. Row.Union r trash (RequestOptions ())
=> URL
-> { | r }
-> Effect ClientRequest
requestURL' url opts = runEffectFn2 requestUrlOptsImpl url opts

foreign import requestUrlOptsImpl :: forall r. EffectFn2 (URL) ({ | r }) (ClientRequest)

requestOpts
:: forall r trash
. Row.Union r trash (RequestOptions ())
=> { | r }
-> Effect ClientRequest
request'' opts = runEffectFn1 requestOptsImpl opts
requestOpts opts = runEffectFn1 requestOptsImpl opts

foreign import requestOptsImpl :: forall r. EffectFn1 ({ | r }) (ClientRequest)

get :: String -> Effect ClientRequest
get url = runEffectFn1 getImpl url
get url = runEffectFn1 getStrImpl url

foreign import getStrImpl :: EffectFn1 (String) (ClientRequest)

foreign import getImpl :: EffectFn1 (String) (ClientRequest)
getUrl :: URL -> Effect ClientRequest
getUrl url = runEffectFn1 getUrlImpl url

foreign import getUrlImpl :: EffectFn1 (URL) (ClientRequest)

get'
:: forall r trash
Expand All @@ -130,16 +151,27 @@ get'
=> String
-> { | r }
-> Effect ClientRequest
get' url opts = runEffectFn2 getUrlOptsImpl url opts
get' url opts = runEffectFn2 getStrOptsImpl url opts

foreign import getStrOptsImpl :: forall r. EffectFn2 (String) ({ | r }) (ClientRequest)

getUrl'
:: forall r trash
. Row.Union r trash (RequestOptions ())
=> Row.Lacks "method" r
=> URL
-> { | r }
-> Effect ClientRequest
getUrl' url opts = runEffectFn2 getUrlOptsImpl url opts

foreign import getUrlOptsImpl :: forall r. EffectFn2 (String) ({ | r }) (ClientRequest)
foreign import getUrlOptsImpl :: forall r. EffectFn2 (URL) ({ | r }) (ClientRequest)

get''
getOpts
:: forall r trash
. Row.Union r trash (RequestOptions ())
=> { | r }
-> Effect ClientRequest
get'' opts = runEffectFn1 getOptsImpl opts
getOpts opts = runEffectFn1 getOptsImpl opts

foreign import getOptsImpl :: forall r. EffectFn1 ({ | r }) (ClientRequest)

Expand Down
8 changes: 6 additions & 2 deletions src/Node/HTTPS.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import https from "node:https";
export const createSecureServer = () => https.createServer();
export const createSecureServerOptsImpl = (opts) => https.createServer(opts);

export const requestImpl = (url) => https.request(url);
export const requestStrImpl = (url) => https.request(url);
export const requestStrOptsImpl = (url, opts) => https.request(url, opts);
export const requestUrlImpl = (url) => https.request(url);
export const requestUrlOptsImpl = (url, opts) => https.request(url, opts);
export const requestOptsImpl = (opts) => https.request(opts);

export const getImpl = (url) => https.get(url);
export const getStrImpl = (url) => https.get(url);
export const getStrOptsImpl = (url, opts) => https.get(url, opts);
export const getUrlImpl = (url) => https.get(url);
export const getUrlOptsImpl = (url, opts) => https.get(url, opts);
export const getOptsImpl = (opts) => https.get(opts);
55 changes: 43 additions & 12 deletions src/Node/HTTPS.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Node.Buffer (Buffer)
import Node.HTTP (CreateServerOptions, RequestOptions)
import Node.HTTP.Types (ClientRequest, HttpServer', Encrypted)
import Node.TLS.Types as TLS
import Node.URL (URL)
import Prim.Row as Row

-- | Example usage. See `createSecureServer'` to pass in options:
Expand Down Expand Up @@ -63,9 +64,14 @@ createSecureServer' opts = runEffectFn1 createSecureServerOptsImpl opts
foreign import createSecureServerOptsImpl :: forall r. EffectFn1 ({ | r }) (HttpServer' Encrypted)

request :: String -> Effect ClientRequest
request url = runEffectFn1 requestImpl url
request url = runEffectFn1 requestStrImpl url

foreign import requestImpl :: EffectFn1 (String) (ClientRequest)
foreign import requestStrImpl :: EffectFn1 (String) (ClientRequest)

requestUrl :: URL -> Effect ClientRequest
requestUrl url = runEffectFn1 requestUrlImpl url

foreign import requestUrlImpl :: EffectFn1 (URL) (ClientRequest)

-- | - `ca` <string> | <string[]> | <Buffer> | <Buffer[]> Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. Mozilla's CAs are completely replaced when CAs are explicitly specified using this option. The value can be a string or Buffer, or an Array of strings and/or Buffers. Any string or Buffer can contain multiple PEM CAs concatenated together. The peer's certificate must be chainable to a CA trusted by the server for the connection to be authenticated. When using certificates that are not chainable to a well-known CA, the certificate's CA must be explicitly specified as a trusted or the connection will fail to authenticate. If the peer uses a certificate that doesn't match or chain to one of the default CAs, use the ca option to provide a CA certificate that the peer's certificate can match or chain to. For self-signed certificates, the certificate is its own CA, and must be provided. For PEM encoded certificates, supported types are "TRUSTED CERTIFICATE", "X509 CERTIFICATE", and "CERTIFICATE". See also tls.rootCertificates.
-- | - `cert` <string> | <string[]> | <Buffer> | <Buffer[]> Cert chains in PEM format. One cert chain should be provided per private key. Each cert chain should consist of the PEM formatted certificate for a provided private key, followed by the PEM formatted intermediate certificates (if any), in order, and not including the root CA (the root CA must be pre-known to the peer, see ca). When providing multiple cert chains, they do not have to be in the same order as their private keys in key. If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail.
Expand Down Expand Up @@ -111,23 +117,38 @@ request'
=> String
-> { | r }
-> Effect ClientRequest
request' url opts = runEffectFn2 requestUrlOptsImpl url opts
request' url opts = runEffectFn2 requestStrOptsImpl url opts

foreign import requestStrOptsImpl :: forall r. EffectFn2 (String) ({ | r }) (ClientRequest)

requestURL'
:: forall r trash
. Row.Union r trash SecureRequestOptions
=> URL
-> { | r }
-> Effect ClientRequest
requestURL' url opts = runEffectFn2 requestUrlOptsImpl url opts

foreign import requestUrlOptsImpl :: forall r. EffectFn2 (String) ({ | r }) (ClientRequest)
foreign import requestUrlOptsImpl :: forall r. EffectFn2 (URL) ({ | r }) (ClientRequest)

request''
requestOpts
:: forall r trash
. Row.Union r trash SecureRequestOptions
=> { | r }
-> Effect ClientRequest
request'' opts = runEffectFn1 requestOptsImpl opts
requestOpts opts = runEffectFn1 requestOptsImpl opts

foreign import requestOptsImpl :: forall r. EffectFn1 ({ | r }) (ClientRequest)

get :: String -> Effect ClientRequest
get url = runEffectFn1 getImpl url
get url = runEffectFn1 getStrImpl url

foreign import getImpl :: EffectFn1 (String) (ClientRequest)
foreign import getStrImpl :: EffectFn1 (String) (ClientRequest)

getUrl :: URL -> Effect ClientRequest
getUrl url = runEffectFn1 getUrlImpl url

foreign import getUrlImpl :: EffectFn1 (URL) (ClientRequest)

get'
:: forall r trash
Expand All @@ -136,16 +157,26 @@ get'
=> String
-> { | r }
-> Effect ClientRequest
get' url opts = runEffectFn2 getUrlOptsImpl url opts
get' url opts = runEffectFn2 getStrOptsImpl url opts

foreign import getUrlOptsImpl :: forall r. EffectFn2 (String) ({ | r }) (ClientRequest)
foreign import getStrOptsImpl :: forall r. EffectFn2 (String) ({ | r }) (ClientRequest)

get''
getUrl'
:: forall r trash
. Row.Union r trash SecureRequestOptions
=> Row.Lacks "method" r
=> URL
-> { | r }
-> Effect ClientRequest
getUrl' url opts = runEffectFn2 getUrlOptsImpl url opts

foreign import getUrlOptsImpl :: forall r. EffectFn2 (URL) ({ | r }) (ClientRequest)

getOpts
:: forall r trash
. Row.Union r trash SecureRequestOptions
=> { | r }
-> Effect ClientRequest
get'' opts = runEffectFn1 getOptsImpl opts
getOpts opts = runEffectFn1 getOptsImpl opts

foreign import getOptsImpl :: forall r. EffectFn1 ({ | r }) (ClientRequest)