@@ -28,14 +28,15 @@ data AuthProtected
2828instance HasServer rest => HasServer (AuthProtected :> rest) where
2929 type ServerT (AuthProtected :> rest) m = ServerT rest m
3030
31− route Proxy a request respond =
32− case lookup "Cookie" (requestHeaders request) of
33− Nothing -> respond . succeedWith $ responseLBS status401 [] "Missing auth header."
34− Just v -> do
35− authGranted <- isGoodCookie v
36− if authGranted
37− then route (Proxy :: Proxy rest) a request respond
38− else respond . succeedWith $ responseLBS status403 [] "Invalid cookie."
31+ route Proxy a = WithRequest $ \ request ->
32+ route (Proxy :: Proxy rest) $ do
33+ case lookup "Cookie" (requestHeaders request) of
34+ Nothing -> return $ failWith $ HttpError status401 (Just "Missing auth header.")
35+ Just v -> do
36+ authGranted <- isGoodCookie v
37+ if authGranted
38+ then a
39+ else return $ failWith $ HttpError status403 (Just "Invalid cookie.")
3940
4041type PrivateAPI = Get '[JSON] [PrivateData]
4142