Last active
September 9, 2016 11:18
-
-
Save tlaitinen/ca5781e36fa2731a070c6a0b327e9491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE RecordWildCards #-} | |
module OnlySecure where | |
import Servant | |
import Data.Typeable | |
import Network.Wai (Request(..)) | |
import Servant.Server.Internal.RoutingApplication ( | |
withRequest, delayedFailFatal, Delayed(..)) | |
import Servant.Server.Internal.RoutingApplication (delayedFailFatal) | |
import Control.Monad (when) | |
data OnlySecure deriving (Typeable) | |
instance HasServer api context => HasServer (OnlySecure :> api) context where | |
type ServerT (OnlySecure :> api) m = ServerT api m | |
route Proxy context subserver = | |
route (Proxy :: Proxy api) context (subserver `addCheck` check) | |
where | |
check = withRequest $ \req -> when (isSecure req == False) $ do | |
delayedFailFatal err403 | |
addCheck Delayed{..} new = | |
Delayed | |
{ authD = new *> authD | |
, .. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment