From b88b905dadbaa50e423a340d5dd676f5b46dd19e Mon Sep 17 00:00:00 2001 From: Connor Prussin Date: Sat, 22 Jul 2017 23:13:47 -0700 Subject: [PATCH] Code cleanup (#54) --- src/HTTPure/Body.purs | 10 ++++------ src/HTTPure/Headers.purs | 5 ++--- src/HTTPure/Server.purs | 5 ++--- test/HTTPure/SpecHelpers.purs | 22 ++++++++++------------ 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/HTTPure/Body.purs b/src/HTTPure/Body.purs index 94c04ec..5cb1feb 100644 --- a/src/HTTPure/Body.purs +++ b/src/HTTPure/Body.purs @@ -25,15 +25,13 @@ read request = Aff.makeAff \_ success -> do let stream = HTTP.requestAsStream request buf <- ST.newSTRef "" Stream.onDataString stream Encoding.UTF8 \str -> - ST.modifySTRef buf ((<>) str) >>= \_ -> pure unit + void $ ST.modifySTRef buf ((<>) str) Stream.onEnd stream $ ST.readSTRef buf >>= success -- | 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 response body = do - _ <- Stream.writeString stream Encoding.UTF8 body noop - Stream.end stream noop - noop +write response body = void do + _ <- Stream.writeString stream Encoding.UTF8 body $ pure unit + Stream.end stream $ pure unit where stream = HTTP.responseAsStream response - noop = pure unit diff --git a/src/HTTPure/Headers.purs b/src/HTTPure/Headers.purs index 820c31c..a123f9a 100644 --- a/src/HTTPure/Headers.purs +++ b/src/HTTPure/Headers.purs @@ -27,9 +27,8 @@ write :: forall e. HTTP.Response -> Headers -> Eff.Eff (http :: HTTP.HTTP | e) Unit -write response headers = do - _ <- Traversable.traverse writeHeader $ StrMap.keys headers - pure unit +write response headers = + void $ Traversable.traverse writeHeader $ StrMap.keys headers where getHeader header = Maybe.fromMaybe "" $ StrMap.lookup header headers writeHeader header = HTTP.setHeader response header $ getHeader header diff --git a/src/HTTPure/Server.purs b/src/HTTPure/Server.purs index 5717408..2772c03 100644 --- a/src/HTTPure/Server.purs +++ b/src/HTTPure/Server.purs @@ -27,11 +27,10 @@ handleRequest :: forall e. HTTP.Request -> HTTP.Response -> ServerM e -handleRequest router request response = do - _ <- Aff.runAff (\_ -> pure unit) (\_ -> pure unit) do +handleRequest router request response = + void $ Aff.runAff (\_ -> pure unit) (\_ -> pure unit) do req <- Request.fromHTTPRequest request EffClass.liftEff $ router req >>= Response.send response - pure unit -- | Given an options object, a function mapping Request to ResponseM, and an -- | HTTPureM containing effects to run on boot, creates and runs a HTTPure diff --git a/test/HTTPure/SpecHelpers.purs b/test/HTTPure/SpecHelpers.purs index 62b1a48..897ab33 100644 --- a/test/HTTPure/SpecHelpers.purs +++ b/test/HTTPure/SpecHelpers.purs @@ -7,7 +7,7 @@ import Control.Monad.Eff as Eff import Control.Monad.Eff.Exception as Exception import Control.Monad.ST as ST import Data.Maybe as Maybe -import Data.Options as Options +import Data.Options ((:=)) import Data.String as StringUtil import Data.StrMap as StrMap import Node.Encoding as Encoding @@ -53,26 +53,24 @@ request :: forall e. String -> String -> Aff.Aff (http :: HTTP.HTTP | e) HTTPClient.Response -request port method headers path body = Aff.makeAff \_ success -> do +request port method headers path body = Aff.makeAff \_ success -> void do req <- HTTPClient.request options success let stream = HTTPClient.requestAsStream req - _ <- Stream.writeString stream Encoding.UTF8 body noop - Stream.end stream noop - noop + _ <- Stream.writeString stream Encoding.UTF8 body $ pure unit + Stream.end stream $ pure unit where - noop = pure unit options = - HTTPClient.method `Options.assoc` method <> - HTTPClient.hostname `Options.assoc` "localhost" <> - HTTPClient.port `Options.assoc` port <> - HTTPClient.path `Options.assoc` path <> - HTTPClient.headers `Options.assoc` HTTPClient.RequestHeaders headers + HTTPClient.method := method <> + HTTPClient.hostname := "localhost" <> + HTTPClient.port := port <> + HTTPClient.path := path <> + HTTPClient.headers := HTTPClient.RequestHeaders headers -- | Given an ST String buffer and a new string, concatenate that new string -- | onto the ST buffer. concat :: forall e s. ST.STRef s String -> String -> Eff.Eff (st :: ST.ST s | e) Unit -concat buf new = ST.modifySTRef buf (\old -> old <> new) >>= (\_ -> pure unit) +concat buf new = void $ ST.modifySTRef buf ((<>) new) -- | Convert a request to an Aff containing the string with the response body. toString :: forall e.