web-routes-happstack-0.23.12.3/0000755000000000000000000000000007346545000014261 5ustar0000000000000000web-routes-happstack-0.23.12.3/LICENSE0000644000000000000000000000275707346545000015301 0ustar0000000000000000Copyright (c)2010, Jeremy Shaw All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Jeremy Shaw nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. web-routes-happstack-0.23.12.3/Setup.hs0000644000000000000000000000005607346545000015716 0ustar0000000000000000import Distribution.Simple main = defaultMain web-routes-happstack-0.23.12.3/Web/Routes/0000755000000000000000000000000007346545000016257 5ustar0000000000000000web-routes-happstack-0.23.12.3/Web/Routes/Happstack.hs0000644000000000000000000000667707346545000020551 0ustar0000000000000000{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances, UndecidableInstances, PackageImports #-} module Web.Routes.Happstack where import Control.Applicative ((<$>)) import Control.Monad (MonadPlus(mzero)) import qualified Data.ByteString.Char8 as C import Data.List (intercalate) import Data.Text (Text) import qualified Data.Text as Text import Happstack.Server (Happstack, FilterMonad(..), ServerMonad(..), WebMonad(..), HasRqData(..), ServerPartT, Response, Request(rqPaths), ToMessage(..), dirs, seeOther) import Web.Routes.RouteT (RouteT(RouteT), MonadRoute, URL, showURL, liftRouteT, mapRouteT) import Web.Routes.Site (Site, runSite) instance (ServerMonad m) => ServerMonad (RouteT url m) where askRq = liftRouteT askRq localRq f m = mapRouteT (localRq f) m instance (FilterMonad a m) => FilterMonad a (RouteT url m) where setFilter = liftRouteT . setFilter composeFilter = liftRouteT . composeFilter getFilter = mapRouteT getFilter instance (WebMonad a m) => WebMonad a (RouteT url m) where finishWith = liftRouteT . finishWith instance (HasRqData m) => HasRqData (RouteT url m) where askRqEnv = liftRouteT askRqEnv localRqEnv f m = mapRouteT (localRqEnv f) m rqDataError = liftRouteT . rqDataError instance (Happstack m) => Happstack (RouteT url m) -- | convert a 'Site' to a normal Happstack route -- -- calls 'mzero' if the route can be decoded. -- -- see also: 'implSite_' implSite :: (Functor m, Monad m, MonadPlus m, ServerMonad m) => Text -- ^ "http://example.org" -> Text -- ^ path to this handler, .e.g. "/route/" or "" -> Site url (m a) -- ^ the 'Site' -> m a implSite domain approot siteSpec = do r <- implSite_ domain approot siteSpec case r of (Left _) -> mzero (Right a) -> return a -- | convert a 'Site' to a normal Happstack route -- -- If url decoding fails, it returns @Left "the parse error"@, -- otherwise @Right a@. -- -- see also: 'implSite' implSite_ :: (Functor m, Monad m, MonadPlus m, ServerMonad m) => Text -- ^ "http://example.org" (or "http://example.org:80") -> Text -- ^ path to this handler, .e.g. "/route/" or "" -> Site url (m a) -- ^ the 'Site' -> m (Either String a) implSite_ domain approot siteSpec = dirs (Text.unpack approot) $ do rq <- askRq let f = runSite (domain `Text.append` approot) siteSpec (map Text.pack $ rqPaths rq) case f of (Left parseError) -> return (Left parseError) (Right sp) -> Right <$> (localRq (const $ rq { rqPaths = [] }) sp) {- implSite__ :: (Monad m) => String -> FilePath -> ([ErrorMsg] -> ServerPartT m a) -> Site url (ServerPartT m a) -> (ServerPartT m a) implSite__ domain approot handleError siteSpec = dirs approot $ do rq <- askRq let pathInfo = intercalate "/" (rqPaths rq) f = runSite (domain ++ approot) siteSpec pathInfo case f of (Failure errs) -> handleError errs (Success sp) -> localRq (const $ rq { rqPaths = [] }) sp -} -- | similar to 'seeOther' but takes a 'URL' 'm' as an argument seeOtherURL :: (MonadRoute m, FilterMonad Response m) => URL m -> m Response seeOtherURL url = do otherURL <- showURL url seeOther (Text.unpack otherURL) (toResponse "") web-routes-happstack-0.23.12.3/web-routes-happstack.cabal0000644000000000000000000000216107346545000021315 0ustar0000000000000000Name: web-routes-happstack Version: 0.23.12.3 License: BSD3 License-File: LICENSE Author: jeremy@seereason.com Maintainer: partners@seereason.com Bug-Reports: http://bugzilla.seereason.com/ Category: Web, Language Synopsis: Adds support for using web-routes with Happstack Description: Added Happstack class instances for RouteT. Provides a default router for Site. Cabal-Version: >= 1.10 Build-type: Simple tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.1, GHC==8.6.5, GHC==8.8.4, GHC==8.10.7, GHC==9.0.2, GHC==9.2.5, GHC==9.4.3 Library Default-language: Haskell2010 Build-Depends: base >= 4 && < 5, bytestring >= 0.9 && < 0.12, happstack-server >= 6.6 && < 7.9, text >= 0.11 && < 2.1, web-routes >= 0.27.1 && < 0.28 Exposed-Modules: Web.Routes.Happstack source-repository head type: git location: https://github.com/Happstack/web-routes-happstack.git