From 435003e2ab3cec5963e6de04e4ac1c4d6c9968fd Mon Sep 17 00:00:00 2001 From: Connor Prussin Date: Sat, 24 Feb 2018 18:51:07 -0800 Subject: [PATCH] Uprev dependencies --- bower.json | 14 +++++++------- src/HTTPure/Body.purs | 6 ++++-- src/HTTPure/Server.purs | 2 +- test/Test/HTTPure/TestHelpers.purs | 11 +++++++---- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/bower.json b/bower.json index 9058831..5d5e407 100644 --- a/bower.json +++ b/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" } } diff --git a/src/HTTPure/Body.purs b/src/HTTPure/Body.purs index a6c98b6..2ff8364 100644 --- a/src/HTTPure/Body.purs +++ b/src/HTTPure/Body.purs @@ -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 diff --git a/src/HTTPure/Server.purs b/src/HTTPure/Server.purs index c73cd99..ed94227 100644 --- a/src/HTTPure/Server.purs +++ b/src/HTTPure/Server.purs @@ -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 diff --git a/test/Test/HTTPure/TestHelpers.purs b/test/Test/HTTPure/TestHelpers.purs index b6bf778..4b2b6d7 100644 --- a/test/Test/HTTPure/TestHelpers.purs +++ b/test/Test/HTTPure/TestHelpers.purs @@ -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.