@@ -1,15 +1,15 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE CPP #-}
2−{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DataKinds #-}
3−{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE FlexibleContexts #-}
4−{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6−{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE OverloadedStrings #-}
7−{-# LANGUAGE PolyKinds #-}
7+{-# LANGUAGE PolyKinds #-}
8−{-# LANGUAGE ScopedTypeVariables #-}
8+{-# LANGUAGE ScopedTypeVariables #-}
9−{-# LANGUAGE TypeFamilies #-}
9+{-# LANGUAGE TypeFamilies #-}
10−{-# LANGUAGE TypeOperators #-}
10+{-# LANGUAGE TypeOperators #-}
11#if !MIN_VERSION_base(4,8,0)
11#if !MIN_VERSION_base(4,8,0)
12−{-# LANGUAGE OverlappingInstances #-}
12+{-# LANGUAGE OverlappingInstances #-}
15module Servant.Server.Internal
15module Servant.Server.Internal
@@ -26,9 +26,9 @@ import Control.Monad.Trans.Except (ExceptT)
26import qualified Data.ByteString as B
26import qualified Data.ByteString as B
27import qualified Data.ByteString.Lazy as BL
27import qualified Data.ByteString.Lazy as BL
28import qualified Data.Map as M
28import qualified Data.Map as M
29−import Data.Maybe (mapMaybe, fromMaybe)
29+import Data.Maybe (fromMaybe, mapMaybe)
30import Data.String (fromString)
30import Data.String (fromString)
31−import Data.String.Conversions (cs, (<>), ConvertibleStrings)
31+import Data.String.Conversions (ConvertibleStrings, cs, (<>))
32import Data.Text (Text)
32import Data.Text (Text)
33import Data.Typeable
33import Data.Typeable
34import GHC.TypeLits (KnownSymbol, symbolVal)
34import GHC.TypeLits (KnownSymbol, symbolVal)
@@ -47,8 +47,8 @@ import Servant.API ((:<|>) (..), (:>), Capture,
47import Servant.API.ContentTypes (AcceptHeader (..),
47import Servant.API.ContentTypes (AcceptHeader (..),
48 AllCTRender (..),
48 AllCTRender (..),
49 AllCTUnrender (..))
49 AllCTUnrender (..))
50−import Servant.API.ResponseHeaders (Headers, getResponse, GetHeaders,
50+import Servant.API.ResponseHeaders (GetHeaders, Headers, getHeaders,
51− getHeaders)
51+ getResponse)
53import Servant.Server.Internal.Router
53import Servant.Server.Internal.Router
54import Servant.Server.Internal.RoutingApplication
54import Servant.Server.Internal.RoutingApplication
@@ -114,7 +114,7 @@ instance (KnownSymbol capture, FromHttpApiData a, HasServer sublayout)
115 route Proxy subserver =
115 route Proxy subserver =
116 DynamicRouter $ \ first -> case captured captureProxy first of
116 DynamicRouter $ \ first -> case captured captureProxy first of
117− Nothing -> LeafRouter (\_ r -> r $ failWith err404)
117+ Nothing -> LeafRouter (\_ r -> r $ Fail err404)
118 Just v -> route (Proxy :: Proxy sublayout) (feedTo subserver v)
118 Just v -> route (Proxy :: Proxy sublayout) (feedTo subserver v)
120 where captureProxy = Proxy :: Proxy (Capture capture a)
120 where captureProxy = Proxy :: Proxy (Capture capture a)
@@ -130,8 +130,8 @@ processMethodRouter :: forall a. ConvertibleStrings a B.ByteString
130 -> Maybe [(HeaderName, B.ByteString)]
130 -> Maybe [(HeaderName, B.ByteString)]
131 -> Request -> RouteResult Response
131 -> Request -> RouteResult Response
132processMethodRouter handleA status method headers request = case handleA of
132processMethodRouter handleA status method headers request = case handleA of
133− Nothing -> failFatallyWith err406
133+ Nothing -> FailFatal err406
134− Just (contentT, body) -> succeedWith $ responseLBS status hdrs bdy
134+ Just (contentT, body) -> Route $! responseLBS status hdrs bdy
136 bdy = if allowedMethodHead method request then "" else body
136 bdy = if allowedMethodHead method request then "" else body
137 hdrs = (hContentType, cs contentT) : (fromMaybe [] headers)
137 hdrs = (hContentType, cs contentT) : (fromMaybe [] headers)
@@ -149,8 +149,8 @@ methodRouter method proxy status action = LeafRouter route'
149 handleA = handleAcceptH proxy (AcceptHeader accH) output
149 handleA = handleAcceptH proxy (AcceptHeader accH) output
150 processMethodRouter handleA status method Nothing request
150 processMethodRouter handleA status method Nothing request
151 | pathIsEmpty request && requestMethod request /= method =
151 | pathIsEmpty request && requestMethod request /= method =
152− respond $ failWith err405
152+ respond $ Fail err405
153− | otherwise = respond $ failWith err404
153+ | otherwise = respond $ Fail err404
155methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v)
155methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v)
156 => Method -> Proxy ctypes -> Status
156 => Method -> Proxy ctypes -> Status
@@ -166,8 +166,8 @@ methodRouterHeaders method proxy status action = LeafRouter route'
166 handleA = handleAcceptH proxy (AcceptHeader accH) (getResponse output)
166 handleA = handleAcceptH proxy (AcceptHeader accH) (getResponse output)
167 processMethodRouter handleA status method (Just headers) request
167 processMethodRouter handleA status method (Just headers) request
168 | pathIsEmpty request && requestMethod request /= method =
168 | pathIsEmpty request && requestMethod request /= method =
169− respond $ failWith err405
169+ respond $ Fail err405
170− | otherwise = respond $ failWith err404
170+ | otherwise = respond $ Fail err404
172methodRouterEmpty :: Method
172methodRouterEmpty :: Method
173 -> IO (RouteResult (ExceptT ServantErr IO ()))
173 -> IO (RouteResult (ExceptT ServantErr IO ()))
@@ -177,10 +177,10 @@ methodRouterEmpty method action = LeafRouter route'
177 route' request respond
177 route' request respond
178 | pathIsEmpty request && allowedMethod method request = do
178 | pathIsEmpty request && allowedMethod method request = do
179 runAction action respond $ \ () ->
179 runAction action respond $ \ () ->
180− succeedWith $ responseLBS noContent204 [] ""
180+ Route $! responseLBS noContent204 [] ""
181 | pathIsEmpty request && requestMethod request /= method =
181 | pathIsEmpty request && requestMethod request /= method =
182− respond $ failWith err405
182+ respond $ Fail err405
183− | otherwise = respond $ failWith err404
183+ | otherwise = respond $ Fail err404
185-- | If you have a 'Delete' endpoint in your API,
185-- | If you have a 'Delete' endpoint in your API,
186-- the handler for this endpoint is meant to delete
186-- the handler for this endpoint is meant to delete
@@ -557,9 +557,9 @@ instance HasServer Raw where
557 route Proxy rawApplication = LeafRouter $ \ request respond -> do
557 route Proxy rawApplication = LeafRouter $ \ request respond -> do
558 r <- rawApplication
558 r <- rawApplication
559 case r of
559 case r of
560− HandlerVal app -> app request (respond . succeedWith)
560+ Route app -> app request (respond . Route)
561− Retriable e -> respond $ failWith e
561+ Fail a -> respond $ Fail a
562− NonRetriable e -> respond $! failFatallyWith e
562+ FailFatal e -> respond $ FailFatal e
564-- | If you use 'ReqBody' in one of the endpoints for your API,
564-- | If you use 'ReqBody' in one of the endpoints for your API,
565-- this automatically requires your server-side handler to be a function
565-- this automatically requires your server-side handler to be a function
@@ -599,8 +599,8 @@ instance ( AllCTUnrender list a, HasServer sublayout
599 mrqbody <- handleCTypeH (Proxy :: Proxy list) (cs contentTypeH)
599 mrqbody <- handleCTypeH (Proxy :: Proxy list) (cs contentTypeH)
600 <$> lazyRequestBody request
600 <$> lazyRequestBody request
601 case mrqbody of
601 case mrqbody of
602− Nothing -> return $! failFatallyWith err415
602+ Nothing -> return $ FailFatal err415
603− Just (Left e) -> return $! failFatallyWith err400 { errBody = cs e }
603+ Just (Left e) -> return $ FailFatal err400 { errBody = cs e }
604 Just (Right v) -> feedTo subserver v
604 Just (Right v) -> feedTo subserver v
606-- | Make sure the incoming request starts with @"/path"@, strip it and
606-- | Make sure the incoming request starts with @"/path"@, strip it and