Uprev dependencies
This commit is contained in:
parent
b6ec731120
commit
435003e2ab
14
bower.json
14
bower.json
@ -17,17 +17,17 @@
|
|||||||
"*.md"
|
"*.md"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"purescript-prelude": "^3.0.0",
|
"purescript-prelude": "^3.1.1",
|
||||||
"purescript-aff": "^3.1.0",
|
"purescript-aff": "^4.0.2",
|
||||||
"purescript-node-fs": "^4.0.0",
|
"purescript-node-fs": "^4.0.0",
|
||||||
"purescript-node-http": "^4.1.0",
|
"purescript-node-http": "^4.2.0",
|
||||||
"purescript-strings": "^3.3.0",
|
"purescript-strings": "^3.5.0",
|
||||||
"purescript-foldable-traversable": "^3.6.0"
|
"purescript-foldable-traversable": "^3.7.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"purescript-psci-support": "^3.0.0",
|
"purescript-psci-support": "^3.0.0",
|
||||||
"purescript-spec": "^1.0.0",
|
"purescript-spec": "^2.0.0",
|
||||||
"purescript-unsafe-coerce": "^3.0.0",
|
"purescript-unsafe-coerce": "^3.0.0",
|
||||||
"purescript-node-fs-aff": "^4.0.0"
|
"purescript-node-fs-aff": "^5.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ module HTTPure.Body
|
|||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
import Data.Either as Either
|
||||||
import Control.Monad.Aff as Aff
|
import Control.Monad.Aff as Aff
|
||||||
import Control.Monad.Eff as Eff
|
import Control.Monad.Eff as Eff
|
||||||
import Control.Monad.ST as ST
|
import Control.Monad.ST as ST
|
||||||
@ -21,12 +22,13 @@ type Body = String
|
|||||||
|
|
||||||
-- | Extract the contents of the body of the HTTP `Request`.
|
-- | Extract the contents of the body of the HTTP `Request`.
|
||||||
read :: forall e. HTTP.Request -> Aff.Aff (HTTPureEffects.HTTPureEffects e) Body
|
read :: forall e. HTTP.Request -> Aff.Aff (HTTPureEffects.HTTPureEffects e) Body
|
||||||
read request = Aff.makeAff \_ success -> do
|
read request = Aff.makeAff \done -> do
|
||||||
let stream = HTTP.requestAsStream request
|
let stream = HTTP.requestAsStream request
|
||||||
buf <- ST.newSTRef ""
|
buf <- ST.newSTRef ""
|
||||||
Stream.onDataString stream Encoding.UTF8 \str ->
|
Stream.onDataString stream Encoding.UTF8 \str ->
|
||||||
void $ ST.modifySTRef buf ((<>) str)
|
void $ ST.modifySTRef buf ((<>) str)
|
||||||
Stream.onEnd stream $ ST.readSTRef buf >>= success
|
Stream.onEnd stream $ ST.readSTRef buf >>= Either.Right >>> done
|
||||||
|
pure $ Aff.nonCanceler
|
||||||
|
|
||||||
-- | Write a `Body` to the given HTTP `Response` and close it.
|
-- | Write a `Body` to the given HTTP `Response` and close it.
|
||||||
write :: forall e. HTTP.Response -> Body -> Eff.Eff (http :: HTTP.HTTP | e) Unit
|
write :: forall e. HTTP.Response -> Body -> Eff.Eff (http :: HTTP.HTTP | e) Unit
|
||||||
|
@ -43,7 +43,7 @@ handleRequest :: forall e.
|
|||||||
HTTP.Response ->
|
HTTP.Response ->
|
||||||
ServerM e
|
ServerM e
|
||||||
handleRequest router request response =
|
handleRequest router request response =
|
||||||
void $ Aff.runAff (\_ -> pure unit) (\_ -> pure unit) do
|
void $ Aff.runAff (\_ -> pure unit) do
|
||||||
req <- Request.fromHTTPRequest request
|
req <- Request.fromHTTPRequest request
|
||||||
router req >>= Response.send response >>> EffClass.liftEff
|
router req >>= Response.send response >>> EffClass.liftEff
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import Control.Monad.Eff as Eff
|
|||||||
import Control.Monad.Eff.Class as EffClass
|
import Control.Monad.Eff.Class as EffClass
|
||||||
import Control.Monad.Eff.Exception as Exception
|
import Control.Monad.Eff.Exception as Exception
|
||||||
import Control.Monad.ST as ST
|
import Control.Monad.ST as ST
|
||||||
|
import Data.Either as Either
|
||||||
import Data.Maybe as Maybe
|
import Data.Maybe as Maybe
|
||||||
import Data.Options ((:=))
|
import Data.Options ((:=))
|
||||||
import Data.String as StringUtil
|
import Data.String as StringUtil
|
||||||
@ -58,11 +59,12 @@ request :: forall e.
|
|||||||
String ->
|
String ->
|
||||||
String ->
|
String ->
|
||||||
Aff.Aff (http :: HTTP.HTTP | e) HTTPClient.Response
|
Aff.Aff (http :: HTTP.HTTP | e) HTTPClient.Response
|
||||||
request secure port method headers path body = Aff.makeAff \_ success -> void do
|
request secure port method headers path body = Aff.makeAff \done -> do
|
||||||
req <- HTTPClient.request options success
|
req <- HTTPClient.request options $ Either.Right >>> done
|
||||||
let stream = HTTPClient.requestAsStream req
|
let stream = HTTPClient.requestAsStream req
|
||||||
_ <- Stream.writeString stream Encoding.UTF8 body $ pure unit
|
_ <- Stream.writeString stream Encoding.UTF8 body $ pure unit
|
||||||
Stream.end stream $ pure unit
|
Stream.end stream $ pure unit
|
||||||
|
pure Aff.nonCanceler
|
||||||
where
|
where
|
||||||
options =
|
options =
|
||||||
HTTPClient.protocol := (if secure then "https:" else "http:") <>
|
HTTPClient.protocol := (if secure then "https:" else "http:") <>
|
||||||
@ -82,11 +84,12 @@ concat buf new = void $ ST.modifySTRef buf ((<>) new)
|
|||||||
-- | Convert a request to an Aff containing the string with the response body.
|
-- | Convert a request to an Aff containing the string with the response body.
|
||||||
toString :: forall e.
|
toString :: forall e.
|
||||||
HTTPClient.Response -> Aff.Aff (HTTPRequestEffects e) String
|
HTTPClient.Response -> Aff.Aff (HTTPRequestEffects e) String
|
||||||
toString response = Aff.makeAff \_ success -> do
|
toString response = Aff.makeAff \done -> do
|
||||||
let stream = HTTPClient.responseAsStream response
|
let stream = HTTPClient.responseAsStream response
|
||||||
buf <- ST.newSTRef ""
|
buf <- ST.newSTRef ""
|
||||||
Stream.onDataString stream Encoding.UTF8 $ concat buf
|
Stream.onDataString stream Encoding.UTF8 $ concat buf
|
||||||
Stream.onEnd stream $ ST.readSTRef buf >>= success
|
Stream.onEnd stream $ ST.readSTRef buf >>= Either.Right >>> done
|
||||||
|
pure $ Aff.nonCanceler
|
||||||
|
|
||||||
-- | Run an HTTP GET with the given url and return an Aff that contains the
|
-- | Run an HTTP GET with the given url and return an Aff that contains the
|
||||||
-- | string with the response body.
|
-- | string with the response body.
|
||||||
|
Loading…
Reference in New Issue
Block a user