File tree 4 files changed +23
-8
lines changed 4 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 20
20
"purescript-maps" : " ^0.5.4" ,
21
21
"purescript-options" : " ^0.6.0" ,
22
22
"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"
24
25
}
25
26
}
Original file line number Diff line number Diff line change 3
3
// module Node.HTTP.Client
4
4
5
5
var http = require ( 'http' ) ;
6
+ var https = require ( 'https' ) ;
6
7
7
8
exports . requestImpl = function ( opts ) {
8
9
return function ( k ) {
9
10
return function ( ) {
10
- return http . request ( opts , function ( res ) {
11
+ var lib = opts . protocol === 'https:' ? https : http ;
12
+ return lib . request ( opts , function ( res ) {
11
13
k ( res ) ( ) ;
12
14
} ) ;
13
15
} ;
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import Data.StrMap (StrMap())
31
31
32
32
import Node.HTTP (HTTP ())
33
33
import Node.Stream (Readable , Writable )
34
+ import Node.URL as URL
34
35
35
36
import Control.Monad.Eff (Eff )
36
37
@@ -84,7 +85,7 @@ request = requestImpl <<< options
84
85
85
86
-- | Make a HTTP request from a URI string and response callback.
86
87
requestFromURI :: forall eff . String -> (Response -> Eff (http :: HTTP | eff ) Unit ) -> Eff (http :: HTTP | eff ) Request
87
- requestFromURI = requestImpl <<< toForeign
88
+ requestFromURI = requestImpl <<< toForeign <<< URL .parse
88
89
89
90
-- | Create a writable stream from a request object.
90
91
requestAsStream :: 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
15
15
foreign import stdout :: forall eff r . Writable r eff
16
16
17
17
main = do
18
+ testBasic
19
+ testHttps
20
+
21
+ testBasic = do
18
22
server <- createServer respond
19
23
listen server 8080 $ void do
20
24
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"
26
26
where
27
27
respond req res = do
28
28
setStatusCode res 200
@@ -41,3 +41,14 @@ main = do
41
41
writeString outputStream UTF8 html(return unit)
42
42
end outputStream (return unit)
43
43
" 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