Merge pull request #1086 from paul-rouse/master

Add guessApprootOr function
This commit is contained in:
Michael Snoyman 2015-10-13 17:27:15 +03:00
commit bc09ac2550
3 changed files with 15 additions and 3 deletions

View File

@ -1,6 +1,6 @@
## 1.4.16 ## 1.4.16
* Add `guessApproot` * Add `guessApproot` and `guessApprootOr`
## 1.4.15.1 ## 1.4.15.1

View File

@ -73,6 +73,7 @@ module Yesod.Core
, defaultLayoutSub , defaultLayoutSub
-- * Approot -- * Approot
, guessApproot , guessApproot
, guessApprootOr
-- * Misc -- * Misc
, yesodVersion , yesodVersion
, yesodRender , yesodRender

View File

@ -835,9 +835,20 @@ fileLocationToString loc = (loc_package loc) ++ ':' : (loc_module loc) ++
-- --
-- Since 1.4.16 -- Since 1.4.16
guessApproot :: Approot site guessApproot :: Approot site
guessApproot = ApprootRequest $ \_master req -> guessApproot = guessApprootOr ApprootRelative
-- | Guess the approot based on request headers, with fall back to the
-- specified 'AppRoot'.
--
-- Since 1.4.16
guessApprootOr :: Approot site -> Approot site
guessApprootOr fallback = ApprootRequest $ \master req ->
case W.requestHeaderHost req of case W.requestHeaderHost req of
Nothing -> "" Nothing -> case fallback of
ApprootRelative -> ""
ApprootStatic t -> t
ApprootMaster f -> f master
ApprootRequest f -> f master req
Just host -> Just host ->
(if Network.Wai.Request.appearsSecure req (if Network.Wai.Request.appearsSecure req
then "https://" then "https://"