@@ -26,19 +26,17 @@ import Control.Monad.Trans.Except (ExceptT)
26
26
import qualified Data.ByteString as B
27
27
import qualified Data.ByteString.Char8 as BC8
28
28
import qualified Data.ByteString.Lazy as BL
29
- import qualified Data.Map as M
30
29
import Data.Maybe (fromMaybe , mapMaybe )
31
30
import Data.String (fromString )
32
31
import Data.String.Conversions (cs , (<>) )
33
- import Data.Text (Text )
34
32
import Data.Typeable
35
33
import GHC.TypeLits (KnownNat , KnownSymbol , natVal ,
36
34
symbolVal )
37
35
import Network.HTTP.Types hiding (Header , ResponseHeaders )
38
36
import Network.Socket (SockAddr )
39
37
import Network.Wai (Application , Request , Response ,
40
38
httpVersion , isSecure ,
41
- lazyRequestBody , pathInfo ,
39
+ lazyRequestBody ,
42
40
rawQueryString , remoteHost ,
43
41
requestHeaders , requestMethod ,
44
42
responseLBS , vault )
@@ -161,34 +159,30 @@ methodRouter :: (AllCTRender ctypes a)
161
159
=> Method -> Proxy ctypes -> Status
162
160
-> Delayed (ExceptT ServantErr IO a )
163
161
-> Router
164
- methodRouter method proxy status action = LeafRouter route'
162
+ methodRouter method proxy status action = leafRouter route'
165
163
where
166
- route' request respond
167
- | pathIsEmpty request =
164
+ route' request respond =
168
165
let accH = fromMaybe ct_wildcard $ lookup hAccept $ requestHeaders request
169
166
in runAction (action `addMethodCheck` methodCheck method request
170
167
`addAcceptCheck` acceptCheck proxy accH
171
168
) respond $ \ output -> do
172
169
let handleA = handleAcceptH proxy (AcceptHeader accH) output
173
170
processMethodRouter handleA status method Nothing request
174
- | otherwise = respond $ Fail err404
175
171
176
172
methodRouterHeaders :: (GetHeaders (Headers h v ), AllCTRender ctypes v )
177
173
=> Method -> Proxy ctypes -> Status
178
174
-> Delayed (ExceptT ServantErr IO (Headers h v ))
179
175
-> Router
180
- methodRouterHeaders method proxy status action = LeafRouter route'
176
+ methodRouterHeaders method proxy status action = leafRouter route'
181
177
where
182
- route' request respond
183
- | pathIsEmpty request =
178
+ route' request respond =
184
179
let accH = fromMaybe ct_wildcard $ lookup hAccept $ requestHeaders request
185
180
in runAction (action `addMethodCheck` methodCheck method request
186
181
`addAcceptCheck` acceptCheck proxy accH
187
182
) respond $ \ output -> do
188
183
let headers = getHeaders output
189
184
handleA = handleAcceptH proxy (AcceptHeader accH) (getResponse output)
190
185
processMethodRouter handleA status method (Just headers) request
191
- | otherwise = respond $ Fail err404
192
186
193
187
instance OVERLAPPABLE_
194
188
( AllCTRender ctypes a , ReflectMethod method , KnownNat status
@@ -359,7 +353,7 @@ instance HasServer Raw context where
359
353
360
354
type ServerT Raw m = Application
361
355
362
- route Proxy _ rawApplication = LeafRouter $ \ request respond -> do
356
+ route Proxy _ rawApplication = RawRouter $ \ request respond -> do
363
357
r <- runDelayed rawApplication
364
358
case r of
365
359
Route app -> app request (respond . Route )
@@ -416,9 +410,10 @@ instance (KnownSymbol path, HasServer sublayout context) => HasServer (path :> s
416
410
417
411
type ServerT (path :> sublayout ) m = ServerT sublayout m
418
412
419
- route Proxy context subserver = StaticRouter $
420
- M. singleton (cs (symbolVal proxyPath))
421
- (route (Proxy :: Proxy sublayout ) context subserver)
413
+ route Proxy context subserver =
414
+ pathRouter
415
+ (cs (symbolVal proxyPath))
416
+ (route (Proxy :: Proxy sublayout ) context subserver)
422
417
where proxyPath = Proxy :: Proxy path
423
418
424
419
instance HasServer api context => HasServer (RemoteHost :> api ) context where
@@ -465,12 +460,6 @@ instance ( KnownSymbol realm
465
460
466
461
-- * helpers
467
462
468
- pathIsEmpty :: Request -> Bool
469
- pathIsEmpty = go . pathInfo
470
- where go [] = True
471
- go [" " ] = True
472
- go _ = False
473
-
474
463
ct_wildcard :: B. ByteString
475
464
ct_wildcard = " *" <> " /" <> " *" -- Because CPP
476
465
0 commit comments