on master help sign in
wai-app-static: added failing test case demonstrating redirection behavior

In conjunction with UrlMap, the missing redirect results in incorrect links in file listings.

commitfdd315d7db4fe291023e7600de3d75b8ac8eff69 authorSönke Hahn <soenkehahn@gmail.com> dateTue 13 Jan 2015, 18:13 (12 years ago) parent90656f6
2 files changed+14−1
wai-app-static/.ghci+1−1 wai-app-static/test/WaiAppStaticTest.hs+13
wai-app-static/.ghci+1−1
@@ -1 +1 @@
1−:set -itest
1+:set -itest -optP-include -optPdist/build/autogen/cabal_macros.h -XCPP
wai-app-static/test/WaiAppStaticTest.hs+13
@@ -14,6 +14,7 @@ import Network.HTTP.Date
1414
1515import Network.Wai
1616import Network.Wai.Test
17+import Network.Wai.UrlMap
1718
1819import Control.Monad.IO.Class (liftIO)
1920import Network.Mime
@@ -123,3 +124,15 @@ spec = do
123124 assertStatus 304 req
124125 assertNoHeader "Cache-Control" req
125126
127+ context "301 redirect to add a trailing slash on directories if missing" $ do
128+ it "works at the root" $ fileServerApp $ do
129+ req <- request (setRawPathInfo defRequest "a")
130+ assertStatus 301 req
131+ assertHeader "Location" "../a/" req
132+
133+ let urlMapApp = flip runSession $ mapUrls $
134+ mount "subPath" (staticApp $ defaultFileServerSettings "test")
135+ it "works in conjunction with UrlMap at the root of the file server" $ urlMapApp $ do
136+ req <- request (setRawPathInfo defRequest "subPath")
137+ assertStatus 301 req
138+ assertHeader "Location" "../subPath/" req