http-pony 0.1.0.4 → 0.1.0.5
raw patch · 3 files changed
+37/−8 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Network.HTTP.Pony.Serve: serveWithSocket :: (MonadIO m) => (Socket, SockAddr) -> (Producer ByteString m () -> m (Producer ByteString m ())) -> m ()
+ Network.HTTP.Pony.Serve: serveWithSocket :: (MonadIO m, MonadCatch m) => (Socket, SockAddr) -> (Producer ByteString m () -> m (Producer ByteString m ())) -> m ()
Files
- ChangeLog.md +9/−1
- http-pony.cabal +2/−1
- src/Network/HTTP/Pony/Serve.hs +26/−6
ChangeLog.md view
@@ -6,4 +6,12 @@ ## 0.1.0.3 -- 2016-09-24 -* Add MonadSafe type for m, this enables resource safe request / repsonse pipes.+* Add MonadSafe type for m, this enables resource safe request / response pipes.++## 0.1.0.4 -- 2016-10-15++* Gives the response producer a way, sending an empty bytestring, to explicitly shutdown the socket and return the control back to the producer.++## 0.1.0.5 -- 2016-10-16++* Handle the exception raised by trying to shutdown an already closed socket.
http-pony.cabal view
@@ -1,5 +1,5 @@ name: http-pony-version: 0.1.0.4+version: 0.1.0.5 synopsis: A type unsafe http library license: BSD3 license-file: LICENSE@@ -36,4 +36,5 @@ -- , lens >= 4.14 hs-source-dirs: src+ -- test default-language: Haskell2010
src/Network/HTTP/Pony/Serve.hs view
@@ -2,10 +2,13 @@ module Network.HTTP.Pony.Serve where +import Control.Exception (IOException)+import Control.Monad.Catch (MonadCatch)+import Control.Monad.Catch (MonadMask) import Control.Monad.IO.Class (MonadIO(..))-import Control.Monad.Catch (MonadMask) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B+import Data.Monoid ((<>)) import qualified Network.Socket as NS import qualified Network.Socket.ByteString as NSB import Pipes (Effect, Producer, Consumer, runEffect, (>->), await)@@ -13,14 +16,14 @@ import Pipes.Network.TCP.Safe (fromSocket, toSocket, connect, connectSock , closeSock) import qualified Pipes.Network.TCP.Safe as PipesNetwork-import Pipes.Safe (MonadSafe(), runSafeT, SafeT)+import Pipes.Safe (MonadSafe(), runSafeT, SafeT, try, catch, throwM) import Network.HTTP.Pony.Helper ((-), shutdownSend, shutdownReceive) import Network.HTTP.Pony.ServeSafe (serveWithPipe) import Prelude hiding ((-), log) -serveWithSocket :: (MonadIO m) => (NS.Socket, NS.SockAddr)+serveWithSocket :: (MonadIO m, MonadCatch m) => (NS.Socket, NS.SockAddr) -> (Producer ByteString m () -> m (Producer ByteString m ())) -> m () serveWithSocket (s,_) =@@ -32,9 +35,26 @@ if B.null x then do- -- liftIO (putStrLn "pony shutdone send")- shutdownSend s- () <$ await+ -- liftIO - do+ -- connected <- NS.isConnected s+ -- putStrLn - "socket connected? " <> show connected+ -- if connected+ -- then do+ -- shutdownSend s+ -- else+ -- pure ()++ let cont = () <$ await+ r <- try (shutdownSend s)+ case r of+ Right _ -> cont+ Left e -> do+ -- liftIO - putStrLn - "Caught: " <> show e++ cont++ throwM (e :: IOException)+ else do liftIO (NSB.send s x) push