Add guessApprootOr function
This commit is contained in:
parent
8e7476cb7a
commit
692773326a
@ -1,6 +1,6 @@
|
|||||||
## 1.4.16
|
## 1.4.16
|
||||||
|
|
||||||
* Add `guessApproot`
|
* Add `guessApproot` and `guessApprootOr`
|
||||||
|
|
||||||
## 1.4.15
|
## 1.4.15
|
||||||
|
|
||||||
|
|||||||
@ -73,6 +73,7 @@ module Yesod.Core
|
|||||||
, defaultLayoutSub
|
, defaultLayoutSub
|
||||||
-- * Approot
|
-- * Approot
|
||||||
, guessApproot
|
, guessApproot
|
||||||
|
, guessApprootOr
|
||||||
-- * Misc
|
-- * Misc
|
||||||
, yesodVersion
|
, yesodVersion
|
||||||
, yesodRender
|
, yesodRender
|
||||||
|
|||||||
@ -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://"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user