Skip to content

Instantly share code, notes, and snippets.

@tlaitinen
Last active September 9, 2016 11:18
Show Gist options
  • Save tlaitinen/ca5781e36fa2731a070c6a0b327e9491 to your computer and use it in GitHub Desktop.
Save tlaitinen/ca5781e36fa2731a070c6a0b327e9491 to your computer and use it in GitHub Desktop.
{-# 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