@@ -1,3 +1,6 @@
1module Network.Wai.Middleware.ForceDomain where
4module Network.Wai.Middleware.ForceDomain where
3import Data.ByteString (ByteString)
6import Data.ByteString (ByteString)
@@ -11,6 +14,8 @@ import Network.Wai.Request
11-- | Force a domain by redirecting.
14-- | Force a domain by redirecting.
12-- The `checkDomain` function takes the current domain and checks whether it is correct.
15-- The `checkDomain` function takes the current domain and checks whether it is correct.
13-- It should return `Nothing` if the domain is correct, or `Just "domain.com"` if it is incorrect.
16-- It should return `Nothing` if the domain is correct, or `Just "domain.com"` if it is incorrect.
14forceDomain :: (ByteString -> Maybe ByteString) -> Middleware
19forceDomain :: (ByteString -> Maybe ByteString) -> Middleware
15forceDomain checkDomain app req sendResponse =
20forceDomain checkDomain app req sendResponse =
16 case requestHeaderHost req >>= checkDomain of
21 case requestHeaderHost req >>= checkDomain of