packages feed

polysemy-http 0.3.1.0 → 0.4.0.0

raw patch · 10 files changed

+29/−24 lines, 10 files

Files

README.md view
@@ -66,9 +66,10 @@ ```haskell data Response b =   Response {-    status :: Status,-    body :: b,-    headers :: [Header]+    _status :: Status,+    _body :: b,+    _headers :: [Header],+    _cookies :: CookieJar   }  data Header =
integration/Polysemy/Http/CookieTest.hs view
@@ -41,4 +41,4 @@ test_cookies = do   result <- lift (withServer runRequest)   response <- evalEither result-  [qt|#{c1}=#{c1v};#{c2}=#{c2v}|] === Response.body response+  [qt|#{c1}=#{c1v};#{c2}=#{c2v}|] === Response._body response
integration/Polysemy/Http/RequestTest.hs view
@@ -35,4 +35,4 @@ test_request = do   result <- lift (withServer runRequest)   response <- evalEither result-  "5" === Response.body response+  "5" === Response._body response
lib/Polysemy/Http.hs view
@@ -77,11 +77,11 @@   Port(..),   QueryKey(..),   QueryValue(..),-  Request(..),+  Request(Request),   Tls(..),   ) import Polysemy.Http.Data.Response (-  Response(..),+  Response(Response),   pattern Client,   pattern Info,   pattern Redirect,
lib/Polysemy/Http/Data/Response.hs view
@@ -3,7 +3,7 @@   Status(Status), ) where -import Network.HTTP.Client (BodyReader)+import Network.HTTP.Client (BodyReader, CookieJar) import Network.HTTP.Types (   Status(Status),   statusIsClientError,@@ -20,16 +20,18 @@ data Response b =   Response {     -- |Uses the type from 'Network.HTTP' for convenience.-    status :: Status,+    _status :: Status,     -- |The body might be evaluated or an 'IO' action.-    body :: b,+    _body :: b,     -- |Does not use the type from 'Network.HTTP' because it is an alias.-    headers :: [Header]+    _headers :: [Header],+    -- |The native cookie jar.+    _cookies :: CookieJar   }   deriving (Eq, Show)  instance {-# overlapping #-} Show (Response BodyReader) where-  show (Response s _ hs) =+  show (Response s _ hs _) =     [qt|StreamingResponse { status :: #{s}, headers :: #{hs} }|]  -- |Match on a response with a 1xx status.@@ -38,7 +40,7 @@   b ->   [Header] ->   Response b-pattern Info s b h <- Response s@(statusIsInformational -> True) b h+pattern Info s b h <- Response s@(statusIsInformational -> True) b h _  -- |Match on a response with a 2xx status. pattern Success ::@@ -46,7 +48,7 @@   b ->   [Header] ->   Response b-pattern Success s b h <- Response s@(statusIsSuccessful -> True) b h+pattern Success s b h <- Response s@(statusIsSuccessful -> True) b h _  -- |Match on a response with a 3xx status. pattern Redirect ::@@ -54,7 +56,7 @@   b ->   [Header] ->   Response b-pattern Redirect s b h <- Response s@(statusIsRedirection -> True) b h+pattern Redirect s b h <- Response s@(statusIsRedirection -> True) b h _  -- |Match on a response with a 4xx status. pattern Client ::@@ -62,7 +64,7 @@   b ->   [Header] ->   Response b-pattern Client s b h <- Response s@(statusIsClientError -> True) b h+pattern Client s b h <- Response s@(statusIsClientError -> True) b h _  -- |Match on a response with a 5xx status. pattern Server ::@@ -70,4 +72,4 @@   b ->   [Header] ->   Response b-pattern Server s b h <- Response s@(statusIsServerError -> True) b h+pattern Server s b h <- Response s@(statusIsServerError -> True) b h _
lib/Polysemy/Http/Http.hs view
@@ -1,7 +1,6 @@ module Polysemy.Http.Http where  import qualified Data.ByteString as ByteString-import Polysemy.Resource (Resource, bracket)  import qualified Polysemy.Http.Data.Http as Http import Polysemy.Http.Data.Http (Http)@@ -11,6 +10,7 @@ import Polysemy.Http.Data.StreamChunk (StreamChunk(StreamChunk)) import qualified Polysemy.Http.Data.StreamEvent as StreamEvent import Polysemy.Http.Data.StreamEvent (StreamEvent)+import Polysemy.Resource (Resource, bracket)  streamLoop ::   Members [Http c, Error HttpError] r =>@@ -18,7 +18,7 @@   Response c ->   h ->   Sem r o-streamLoop process response@(Response _ body _) handle =+streamLoop process response@(Response _ body _ _) handle =   spin   where     spin =
lib/Polysemy/Http/Native.hs view
@@ -54,7 +54,7 @@  convertResponse :: HTTP.Response b -> Response b convertResponse response =-  Response (HTTP.responseStatus response) (HTTP.responseBody response) headers+  Response (HTTP.responseStatus response) (HTTP.responseBody response) headers (HTTP.responseCookieJar response)   where     headers =       header <$> HTTP.responseHeaders response
lib/Polysemy/Http/Strict.hs view
@@ -7,6 +7,7 @@ import qualified Polysemy.Http.Data.Http as Http import Polysemy.Http.Data.Http (Http) import Polysemy.Http.Data.Response (Response(Response))+import Network.HTTP.Client.Internal (CookieJar(CJ))  takeResponse ::   Member (State [Response LByteString]) r =>@@ -15,7 +16,7 @@ takeResponse (response : rest) =   response <$ put rest takeResponse [] =-  pure (Response (toEnum 502) "test responses exhausted" [])+  pure (Response (toEnum 502) "test responses exhausted" [] (CJ mempty))  takeChunk ::   Member (State [ByteString]) r =>@@ -31,7 +32,7 @@   Response (toEnum 200) "stream response" [     Header "content-disposition" [qt|filename="file.txt"|],     Header "content-length" "5000000"-    ]+    ] (CJ mempty)  interpretHttpStrictWithState ::   Members [State [ByteString], State [Response LByteString], Embed IO] r =>
polysemy-http.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           polysemy-http-version:        0.3.1.0+version:        0.4.0.0 synopsis:       Polysemy effect for http-client description:    Please see the README on Github at <https://github.com/tek/polysemy-http> category:       Network
test/Polysemy/Http/ResponseTest.hs view
@@ -1,6 +1,7 @@ module Polysemy.Http.ResponseTest where  import Hedgehog ((===))+import Network.HTTP.Client.Internal (CookieJar(CJ))  import qualified Polysemy.Http.Data.Response as Response import Polysemy.Http.Data.Response (Response(Response))@@ -8,7 +9,7 @@  response :: Response () response =-  Response (toEnum 404) () []+  Response (toEnum 404) () [] (CJ mempty)  match :: Response a -> Int match = \case