Uprev dependencies
This commit is contained in:
parent
b6ec731120
commit
435003e2ab
14
bower.json
14
bower.json
@ -17,17 +17,17 @@
|
||||
"*.md"
|
||||
],
|
||||
"dependencies": {
|
||||
"purescript-prelude": "^3.0.0",
|
||||
"purescript-aff": "^3.1.0",
|
||||
"purescript-prelude": "^3.1.1",
|
||||
"purescript-aff": "^4.0.2",
|
||||
"purescript-node-fs": "^4.0.0",
|
||||
"purescript-node-http": "^4.1.0",
|
||||
"purescript-strings": "^3.3.0",
|
||||
"purescript-foldable-traversable": "^3.6.0"
|
||||
"purescript-node-http": "^4.2.0",
|
||||
"purescript-strings": "^3.5.0",
|
||||
"purescript-foldable-traversable": "^3.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"purescript-psci-support": "^3.0.0",
|
||||
"purescript-spec": "^1.0.0",
|
||||
"purescript-spec": "^2.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 Data.Either as Either
|
||||
import Control.Monad.Aff as Aff
|
||||
import Control.Monad.Eff as Eff
|
||||
import Control.Monad.ST as ST
|
||||
@ -21,12 +22,13 @@ type Body = String
|
||||
|
||||
-- | Extract the contents of the body of the HTTP `Request`.
|
||||
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
|
||||
buf <- ST.newSTRef ""
|
||||
Stream.onDataString stream Encoding.UTF8 \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 :: forall e. HTTP.Response -> Body -> Eff.Eff (http :: HTTP.HTTP | e) Unit
|
||||
|
@ -43,7 +43,7 @@ handleRequest :: forall e.
|
||||
HTTP.Response ->
|
||||
ServerM e
|
||||
handleRequest router request response =
|
||||
void $ Aff.runAff (\_ -> pure unit) (\_ -> pure unit) do
|
||||
void $ Aff.runAff (\_ -> pure unit) do
|
||||
req <- Request.fromHTTPRequest request
|
||||
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.Exception as Exception
|
||||
import Control.Monad.ST as ST
|
||||
import Data.Either as Either
|
||||
import Data.Maybe as Maybe
|
||||
import Data.Options ((:=))
|
||||
import Data.String as StringUtil
|
||||
@ -58,11 +59,12 @@ request :: forall e.
|
||||
String ->
|
||||
String ->
|
||||
Aff.Aff (http :: HTTP.HTTP | e) HTTPClient.Response
|
||||
request secure port method headers path body = Aff.makeAff \_ success -> void do
|
||||
req <- HTTPClient.request options success
|
||||
request secure port method headers path body = Aff.makeAff \done -> do
|
||||
req <- HTTPClient.request options $ Either.Right >>> done
|
||||
let stream = HTTPClient.requestAsStream req
|
||||
_ <- Stream.writeString stream Encoding.UTF8 body $ pure unit
|
||||
Stream.end stream $ pure unit
|
||||
pure Aff.nonCanceler
|
||||
where
|
||||
options =
|
||||
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.
|
||||
toString :: forall e.
|
||||
HTTPClient.Response -> Aff.Aff (HTTPRequestEffects e) String
|
||||
toString response = Aff.makeAff \_ success -> do
|
||||
toString response = Aff.makeAff \done -> do
|
||||
let stream = HTTPClient.responseAsStream response
|
||||
buf <- ST.newSTRef ""
|
||||
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
|
||||
-- | string with the response body.
|
||||
|
Loading…
Reference in New Issue
Block a user