File tree Expand file tree Collapse file tree 4 files changed +23
-8
lines changed Expand file tree Collapse file tree 4 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 2020 "purescript-maps" : " ^0.5.4" ,
2121 "purescript-options" : " ^0.6.0" ,
2222 "purescript-unsafe-coerce" : " ^0.1.0" ,
23- "purescript-node-streams" : " ^0.3.0"
23+ "purescript-node-streams" : " ^0.3.0" ,
24+ "purescript-node-url" : " ^0.1.1"
2425 }
2526}
Original file line number Diff line number Diff line change 33// module Node.HTTP.Client
44
55var http = require ( 'http' ) ;
6+ var https = require ( 'https' ) ;
67
78exports . requestImpl = function ( opts ) {
89 return function ( k ) {
910 return function ( ) {
10- return http . request ( opts , function ( res ) {
11+ var lib = opts . protocol === 'https:' ? https : http ;
12+ return lib . request ( opts , function ( res ) {
1113 k ( res ) ( ) ;
1214 } ) ;
1315 } ;
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import Data.StrMap (StrMap())
3131
3232import Node.HTTP (HTTP ())
3333import Node.Stream (Readable , Writable )
34+ import Node.URL as URL
3435
3536import Control.Monad.Eff (Eff )
3637
@@ -84,7 +85,7 @@ request = requestImpl <<< options
8485
8586-- | Make a HTTP request from a URI string and response callback.
8687requestFromURI :: forall eff . String -> (Response -> Eff (http :: HTTP | eff ) Unit ) -> Eff (http :: HTTP | eff ) Request
87- requestFromURI = requestImpl <<< toForeign
88+ requestFromURI = requestImpl <<< toForeign <<< URL .parse
8889
8990-- | Create a writable stream from a request object.
9091requestAsStream :: forall eff r . Request -> Writable r (http :: HTTP | eff )
Original file line number Diff line number Diff line change @@ -15,14 +15,14 @@ import Node.Encoding
1515foreign import stdout :: forall eff r . Writable r eff
1616
1717main = do
18+ testBasic
19+ testHttps
20+
21+ testBasic = do
1822 server <- createServer respond
1923 listen server 8080 $ void do
2024 log " Listening on port 8080."
21- req <- Client .requestFromURI " http://localhost:8080/" \response -> void do
22- log " Response from GET /:"
23- let responseStream = Client .responseAsStream response
24- pipe responseStream stdout
25- end (Client .requestAsStream req) (return unit)
25+ simpleReq " http://localhost:8080"
2626 where
2727 respond req res = do
2828 setStatusCode res 200
@@ -41,3 +41,14 @@ main = do
4141 writeString outputStream UTF8 html(return unit)
4242 end outputStream (return unit)
4343 " POST" -> void $ pipe inputStream outputStream
44+
45+ testHttps =
46+ simpleReq " https://api.github.com"
47+
48+ simpleReq uri = do
49+ log (" GET " <> uri <> " :" )
50+ req <- Client .requestFromURI uri \response -> void do
51+ log " Response:"
52+ let responseStream = Client .responseAsStream response
53+ pipe responseStream stdout
54+ end (Client .requestAsStream req) (return unit)
You can’t perform that action at this time.
0 commit comments