packages feed

http-pony 0.1.0.1 → 0.1.0.2

raw patch · 6 files changed

+30/−164 lines, 6 filesdep −attoparsecdep −case-insensitivedep −pipes-attoparsecdep ~bytestringPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies removed: attoparsec, case-insensitive, pipes-attoparsec, pipes-parse

Dependency ranges changed: bytestring

API changes (from Hackage documentation)

- Network.HTTP.Pony.Builder: header :: Monad m => Header -> Producer ByteString m ()
- Network.HTTP.Pony.Builder: message :: Monad m => Request ByteString m r -> Producer ByteString m r
- Network.HTTP.Pony.Parser: header :: Parser Header
- Network.HTTP.Pony.Parser: headers :: Parser [Header]
- Network.HTTP.Pony.Parser: message :: Parser (ByteString, [Header])
- Network.HTTP.Pony.Parser: parseMessage :: (Monad m) => Producer ByteString m r -> m a -> m (Maybe (Either ParsingError (Message ByteString m r)))
- Network.HTTP.Pony.Parser: requestLine :: Parser ByteString
- Network.HTTP.Pony.Parser: startLine :: Parser ByteString
- Network.HTTP.Pony.Parser: statusLine :: Parser ByteString
- Network.HTTP.Pony.Parser: token :: Parser ByteString
- Network.HTTP.Pony.Serve: http :: (Monad m) => Middleware m (Producer ByteString m a) (Producer ByteString m ()) (Request ByteString m a) (Response ByteString m b)
- Network.HTTP.Pony.Type: type Application' m a x = Application m a a x x
- Network.HTTP.Pony.Type: type Application'' m a = Application m a a () ()
- Network.HTTP.Pony.Type: type Header = (CI ByteString, ByteString)
- Network.HTTP.Pony.Type: type Message a m r = (StartLine, [Header], Producer a m r)
- Network.HTTP.Pony.Type: type Request a m r = Message a m r
- Network.HTTP.Pony.Type: type Response a m r = Message a m r
- Network.HTTP.Pony.Type: type StartLine = ByteString
- Network.HTTP.Pony.Type: type App = Application'' IO ByteString
+ Network.HTTP.Pony.Type: type App m = Application m ByteString ByteString () ()
- Network.HTTP.Pony.Type: type Application m a b x y = Request a m x -> m (Response b m y)
+ Network.HTTP.Pony.Type: type Application m a b s t = Producer a m s -> m (Producer b m t)

Files

README.md view
@@ -9,32 +9,34 @@      import Pipes (yield) -    hello _ = pure ("HTTP/1.1 200 OK", [], yield "hello world\n")+    hello _ = pure (("HTTP/1.1 200 OK", []), yield "hello world\n") + Note, we are not importing any interface!  If we take a closer look at the type of `hello`: -    Prelude Hello> :t hello+    Prelude Hello> :t hello      hello       :: (Applicative f, Data.String.IsString a, Data.String.IsString t,           Monad m) =>-        t2 -> f (t, [t1], Pipes.Internal.Proxy x' x () a m ())+        t2 -> f ((t, [t1]), Pipes.Internal.Proxy x' x () a m ())  This is a *pure* app!  Shall we run it? -{-# LANGUAGE OverloadedStrings #-}+    {-# LANGUAGE OverloadedStrings #-}      module RunHello where -    import Network.HTTP.Pony.Serve (run, http)+    import Hello (hello)+    import Network.HTTP.Pony.Serve (run)+    import Network.HTTP.Pony.Transformer.HTTP (http)     import Pipes.Safe (runSafeT)-    import PonyHello (ponyHello)      main :: IO ()-    main = (runSafeT . run "localhost" "8080" . http) ponyHello+    main = (runSafeT . run "localhost" "8080" . http) hello  Test it: 
http-pony.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                http-pony-version:             0.1.0.1+version:             0.1.0.2 synopsis:            A type unsafe http library -- description:          license:             BSD3@@ -19,23 +19,28 @@  library   exposed-modules:     Network.HTTP.Pony.Type-                     , Network.HTTP.Pony.Builder                      , Network.HTTP.Pony.Serve-                     , Network.HTTP.Pony.Parser                      , Network.HTTP.Pony.Helper+                     -- , Network.HTTP.Pony.Transformer   -- other-modules:          -- other-extensions:    OverloadedStrings-  build-depends:       attoparsec >=0.13-                     , base >=4.9 && <4.10-                     , bytestring >=0.10 && <0.11-                     , case-insensitive >=1.2-                     , network >=2.6-                     , pipes >=4.1-                     , pipes-attoparsec >=0.5-                     , pipes-network >=0.6-                     , pipes-parse >=3.0-                     , pipes-safe >=2.2-                     , transformers >=0.5+  build-depends:       ++                         base >=4.9 && <4.10+                       , bytestring >=0.10+                       , network >=2.6+                       , pipes >=4.1+                       , pipes-network >=0.6+                       , pipes-safe >=2.2+                       -- , profunctors >= 5.2+                       , transformers >=0.5+++                       -- , case-insensitive >= 1.2.0.7+                       -- , foreign-store >= 0.2+                       -- , http-pony-transformer-case-insensitive+                       -- , http-pony-transformer-http+                       -- , lens >= 4.14    hs-source-dirs:      src   default-language:    Haskell2010
− src/Network/HTTP/Pony/Builder.hs
@@ -1,36 +0,0 @@--- | Builder--{-# LANGUAGE OverloadedStrings #-}--module Network.HTTP.Pony.Builder where--import           Data.ByteString (ByteString)-import qualified Data.CaseInsensitive as CI-import           Pipes as Pipes-import qualified Pipes.Attoparsec as AttoParser-import           Pipes.Network.TCP.Safe-import qualified Pipes.Parse as Parser-import           Pipes.Prelude (tee)-import qualified Pipes.Prelude as Pipes--import           Network.HTTP.Pony.Helper ((-))-import           Network.HTTP.Pony.Type-import           Prelude hiding ((-), log)--header :: Monad m => Header -> Producer ByteString m ()-header (key, value) = do-  yield - CI.original key-  yield ": "-  yield value-  yield "\n"---message :: Monad m => Request ByteString m r -> Producer ByteString m r-message (startLine, headers, body) = do-  yield startLine-  yield "\n"--  Pipes.each ~> header - headers--  yield "\n"-  body
− src/Network/HTTP/Pony/Parser.hs
@@ -1,59 +0,0 @@--- | Parser--module Network.HTTP.Pony.Parser where--import           Control.Applicative ((<|>))-import           Control.Monad.Trans.State.Strict (runStateT)-import           Data.Attoparsec.ByteString-import qualified Data.Attoparsec.ByteString.Char8 as Char-import           Data.ByteString.Char8 (ByteString)-import qualified Data.ByteString.Char8 as B-import qualified Data.CaseInsensitive as CI-import           Pipes (Producer)-import           Pipes.Attoparsec (ParsingError(..))-import qualified Pipes.Attoparsec as PA--import           Network.HTTP.Pony.Helper ((-))-import           Network.HTTP.Pony.Type-import           Prelude hiding ((-))---- https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2---startLine :: Parser ByteString-startLine = takeTill Char.isEndOfLine <* Char.endOfLine--requestLine :: Parser ByteString-requestLine = startLine--statusLine :: Parser ByteString-statusLine = startLine--headers :: Parser [Header]-headers = do-  many' header <* Char.endOfLine--token :: Parser ByteString-token = fmap B.pack - many1' (Char.letter_ascii <|> Char.char '-')--header :: Parser Header-header = do-  fieldName <- token-  Char.char ':'-  Char.skipSpace-  fieldValue <- takeTill Char.isEndOfLine-  Char.endOfLine-  pure (CI.mk fieldName, fieldValue)--message :: Parser (ByteString, [Header])-message = do-  Char.skipSpace-  (,) <$> startLine <*> headers--parseMessage :: (Monad m) => Producer ByteString m r-                          -> m a-                          -> m (Maybe (Either ParsingError (Message ByteString m r)))-parseMessage p errHandler = do-  (r, body) <- runStateT (PA.parse message) p--  pure - fmap (fmap (\(x, xs) -> (x, xs, body))) r
src/Network/HTTP/Pony/Serve.hs view
@@ -8,39 +8,13 @@ import           Data.ByteString.Char8 (ByteString) import qualified Network.Socket as NS import           Pipes (Producer, Consumer, runEffect, (>->))-import           Pipes.Attoparsec (ParsingError(..)) import           Pipes.Network.TCP.Safe (HostPreference()) import           Pipes.Network.TCP.Safe (fromSocket, toSocket) import qualified Pipes.Network.TCP.Safe as PipesNetwork import           Pipes.Safe (MonadSafe(), runSafeT) -import qualified Network.HTTP.Pony.Builder as Builder import           Network.HTTP.Pony.Helper ((-), shutdownSend, shutdownReceive)-import qualified Network.HTTP.Pony.Parser as Parser-import           Network.HTTP.Pony.Type (Application, App, Middleware, Request, Response) import           Prelude hiding ((-), log)---- http :: (Monad m) => Application m ByteString ByteString a b---                   -> (Producer ByteString m a -> m (Producer ByteString m ()))-http :: (Monad m) => Middleware m-                                (Producer ByteString m a)-                                (Producer ByteString m ())-                                (Request ByteString m a)-                                (Response ByteString m b)-http app pull = do-  maybeRequest <- Parser.parseMessage pull (pure ())--  case maybeRequest of-    Just (Right request) -> do-      response <- app request--      pure - Builder.message response >> pure ()--    _ -> pure - pure ()--    -- Just (Left err) -> pure - pure - err-    -- _ -> pure Nothing-  serveWithPipe :: (Monad m)  => Producer ByteString m a                             -> Consumer ByteString m b
src/Network/HTTP/Pony/Type.hs view
@@ -1,30 +1,10 @@-{-# LANGUAGE Rank2Types #-}- module Network.HTTP.Pony.Type where  import Data.ByteString (ByteString)-import Data.CaseInsensitive (CI)-import Network.Socket (Socket) import Pipes (Producer) -type StartLine = ByteString-type Header = (CI ByteString, ByteString)--type Message a m r = (StartLine, [Header], Producer a m r)--type Request a m r = Message a m r-type Response a m r = Message a m r---- App shouldn't block!-type Application m a b x y = Request a m x -> m (Response b m y)-type Application' m a x = Application m a a x x-type Application'' m a = Application m a a () ()--type App = Application'' IO ByteString---- type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t--- A Middleware is a Lens on Message?+type Application m a b s t = Producer a m s -> m (Producer b m t)+type App m = Application m ByteString ByteString () () --- type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t type Middleware f s t a b = (a -> f b) -> s -> f t type Middleware' f s t = (s -> f t) -> s -> f t