packages feed

firefly 0.1.0.1 → 0.1.1.0

raw patch · 4 files changed

+14/−11 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Web.Firefly: pathMatches :: ReqReader m => Pattern -> m Bool
+ Web.Firefly.Request: pathMatches :: ReqReader m => Pattern -> m Bool

Files

firefly.cabal view
@@ -1,5 +1,5 @@ name:                firefly-version:             0.1.0.1+version:             0.1.1.0 synopsis:            A simple HTTP server framework -- description: homepage:            https://github.com/ChrisPenner/firefly#readme
src/Web/Firefly.hs view
@@ -29,6 +29,7 @@   , getCookie   , isSecure   , waiRequest+  , pathMatches    -- * Responses   , ToResponse(..)
src/Web/Firefly/Handler.hs view
@@ -10,11 +10,7 @@ import Web.Firefly.Request import Web.Firefly.Response import Control.Monad-import Control.Monad.Trans-import qualified Data.Text as T -import Text.Regex.PCRE- -- | Run a handler on a matching route. -- The handler may return any type which implements 'ToResponse' --@@ -34,9 +30,5 @@ -- >   route "/helloHarry" helloHarryHandler route :: (ToResponse r) => Pattern -> Handler r -> App () route routePath handler = do-  path <- getPath-  when (routePath `matches` path) (handler >>= respond . toResponse)---- | Determine whether a route matches a pattern-matches :: Route -> Pattern -> Bool-matches (T.unpack -> rt) (T.unpack -> pat) = ("^" ++ pat ++ "$") =~ rt+  doesPathMatch <- pathMatches routePath+  when doesPathMatch (handler >>= respond . toResponse)
src/Web/Firefly/Request.hs view
@@ -2,6 +2,7 @@ {-# language FlexibleContexts #-} {-# language ConstraintKinds #-} {-# language RankNTypes #-}+{-# language ViewPatterns #-} module Web.Firefly.Request   ( getPath   , getPathInfo@@ -20,6 +21,7 @@   , getCookie   , isSecure   , waiRequest+  , pathMatches   ) where  import Control.Monad.Reader@@ -28,6 +30,7 @@ import qualified Data.Text as T import qualified Data.Map as M import qualified Data.CaseInsensitive as CI+import Text.Regex.PCRE  import Web.Cookie import qualified Network.Wai as W@@ -118,3 +121,10 @@ -- | Exposes the underlying 'W.Request'. waiRequest :: ReqReader m =>  m W.Request waiRequest = asks request++-- | Determine whether a route matches a pattern+pathMatches :: ReqReader m => Pattern -> m Bool+pathMatches pattern = checkMatch pattern <$> getPath +  where+    checkMatch :: Pattern -> Route -> Bool+    checkMatch (T.unpack -> pat) (T.unpack -> rt) = ("^" ++ pat ++ "$") =~ rt