packages feed

wai-extra 3.0.13.1 → 3.0.14

raw patch · 4 files changed

+45/−1 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Network.Wai.Middleware.ForceDomain: forceDomain :: (ByteString -> Maybe ByteString) -> Middleware

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 3.0.14++* Middleware to force domain names. [#506](https://github.com/yesodweb/wai/issues/506) [#507](https://github.com/yesodweb/wai/pull/507)+ ## 3.0.13.1  * Support wai 3.2
+ Network/Wai/Middleware/ForceDomain.hs view
@@ -0,0 +1,38 @@+-- |+--+-- @since 3.0.14+module Network.Wai.Middleware.ForceDomain where++import Data.ByteString (ByteString)+import Data.Monoid ((<>), mempty)+import Network.HTTP.Types (hLocation, methodGet, status301, status307)+import Prelude++import Network.Wai+import Network.Wai.Request++-- | Force a domain by redirecting.+-- The `checkDomain` function takes the current domain and checks whether it is correct.+-- It should return `Nothing` if the domain is correct, or `Just "domain.com"` if it is incorrect.+--+-- @since 3.0.14+forceDomain :: (ByteString -> Maybe ByteString) -> Middleware+forceDomain checkDomain app req sendResponse =+    case requestHeaderHost req >>= checkDomain of+        Nothing ->+            app req sendResponse+        Just domain ->+            sendResponse $ redirectResponse domain++    where+        -- From: Network.Wai.Middleware.ForceSSL+        redirectResponse domain =+            responseBuilder status [(hLocation, location domain)] mempty++        location h =+            let p = if appearsSecure req then "https://" else "http://" in+            p <> h <> rawPathInfo req <> rawQueryString req++        status+            | requestMethod req == methodGet = status301+            | otherwise = status307
Network/Wai/Middleware/Gzip.hs view
@@ -65,6 +65,7 @@         [ "application/json"         , "application/javascript"         , "application/ecmascript"+        , "image/x-icon"         ]  -- | Use gzip to compress the body of the response.
wai-extra.cabal view
@@ -1,5 +1,5 @@ Name:                wai-extra-Version:             3.0.13.1+Version:             3.0.14 Synopsis:            Provides some basic WAI handlers and middleware. description:   Provides basic WAI handler and middleware functionality:@@ -141,6 +141,7 @@                      Network.Wai.Middleware.Vhost                      Network.Wai.Middleware.HttpAuth                      Network.Wai.Middleware.StreamFile+                     Network.Wai.Middleware.ForceDomain                      Network.Wai.Middleware.ForceSSL                      Network.Wai.Middleware.Routed                      Network.Wai.Parse