git.iko.soy/typeable/servant
on master help sign in
refactored HasServer Capture instance
b4eef7aSönke Hahn
servant-server/src/Servant/Server/Internal.hs+1−6
@@ -99,9 +99,6 @@ instance (HasServer a context, HasServer b context) => HasServer (a :<|> b) cont
99 where pa = Proxy :: Proxy a
99 where pa = Proxy :: Proxy a
100 pb = Proxy :: Proxy b
100 pb = Proxy :: Proxy b
101
101
102−captured :: FromHttpApiData a => proxy (Capture sym a) -> Text -> Maybe a
103−captured _ = parseUrlPieceMaybe
104−
105-- | If you use 'Capture' in one of the endpoints for your API,
102-- | If you use 'Capture' in one of the endpoints for your API,
106-- this automatically requires your server-side handler to be a function
103-- this automatically requires your server-side handler to be a function
107-- that takes an argument of the type specified by the 'Capture'.
104-- that takes an argument of the type specified by the 'Capture'.
@@ -129,12 +126,10 @@ instance (KnownSymbol capture, FromHttpApiData a, HasServer sublayout context)
129 DynamicRouter $ \ first ->
126 DynamicRouter $ \ first ->
130 route (Proxy :: Proxy sublayout)
127 route (Proxy :: Proxy sublayout)
131 context
128 context
132− (addCapture d $ case captured captureProxy first of
129+ (addCapture d $ case parseUrlPieceMaybe first :: Maybe a of
133 Nothing -> return $ Fail err404
130 Nothing -> return $ Fail err404
134 Just v -> return $ Route v
131 Just v -> return $ Route v
135 )
132 )
136− where
137− captureProxy = Proxy :: Proxy (Capture capture a)
138
133
139allowedMethodHead :: Method -> Request -> Bool
134allowedMethodHead :: Method -> Request -> Bool
140allowedMethodHead method request = method == methodGet && requestMethod request == methodHead
135allowedMethodHead method request = method == methodGet && requestMethod request == methodHead