packages feed

wai-app-static 3.0.0.5 → 3.0.0.6

raw patch · 4 files changed

+42/−5 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 3.0.0.6++Fix trailing slashes for `UrlMap` and other non-root setups [#325](https://github.com/yesodweb/wai/issues/325)+ ## 3.0.0.4  Add missing trailing slashes [#312](https://github.com/yesodweb/wai/issues/312)
Network/Wai/Application/Static.hs view
@@ -52,6 +52,7 @@ data StaticResponse =       -- | Just the etag hash or Nothing for no etag hash       Redirect Pieces (Maybe ByteString)+    | RawRedirect ByteString     | NotFound     | FileResponse File H.ResponseHeaders     | NotModified@@ -79,15 +80,15 @@             let pieces' = setLast pieces index in             case () of               () | ssRedirectToIndex -> return $ Redirect pieces' Nothing-                 | noTrailingSlash pieces, Just trailing <- toPiece ""  ->-                    return $ Redirect (pieces ++ [trailing]) Nothing+                 | Just path <- addTrailingSlash req ->+                    return $ RawRedirect path                  | otherwise ->                     -- start the checking process over, with a new set                     checkPieces ss pieces' req         Nothing ->             case ssListing of-                Just _ | noTrailingSlash pieces, Just trailing <- toPiece "" ->-                    return $ Redirect (pieces ++ [trailing]) Nothing+                Just _ | Just path <- addTrailingSlash req ->+                    return $ RawRedirect path                 Just listing -> do                     -- directory listings turned on, display it                     builder <- listing pieces folder@@ -104,6 +105,14 @@         | fromPiece t == "" = [x]     setLast (a:b) x = a : setLast b x +    addTrailingSlash :: W.Request -> Maybe ByteString+    addTrailingSlash req+        | S8.null rp = Just "/"+        | S8.last rp == '/' = Nothing+        | otherwise = Just $ S8.snoc rp '/'+      where+        rp = W.rawPathInfo req+     noTrailingSlash :: Pieces -> Bool     noTrailingSlash [] = False     noTrailingSlash [x] = fromPiece x /= ""@@ -248,6 +257,12 @@             sendResponse $ W.responseLBS H.status301                 [ ("Content-Type", "text/plain")                 , ("Location", S8.append loc $ H.renderQuery True qString)+                ] "Redirect"++    response (RawRedirect path) =+            sendResponse $ W.responseLBS H.status301+                [ ("Content-Type", "text/plain")+                , ("Location", path)                 ] "Redirect"      response NotFound = sendResponse $ W.responseLBS H.status404
test/WaiAppStaticTest.hs view
@@ -9,6 +9,7 @@ import System.PosixCompat.Files (getFileStatus, modificationTime)  import Network.HTTP.Date+import Network.HTTP.Types (status500) {-import System.Locale (defaultTimeLocale)-} {-import Data.Time.Format (formatTime)-} @@ -123,3 +124,20 @@       assertStatus 304 req       assertNoHeader "Cache-Control" req +    context "301 redirect to add a trailing slash on directories if missing" $ do+      it "works at the root" $ fileServerApp $ do+        req <- request (setRawPathInfo defRequest "/a")+        assertStatus 301 req+        assertHeader "Location" "/a/" req++      let urlMapApp = flip runSession $ \req send ->+            case pathInfo req of+                "subPath":rest ->+                    let req' = req { pathInfo = rest }+                     in (staticApp $ defaultFileServerSettings "test") req' send+                _ -> send $ responseLBS status500 []+                    "urlMapApp: only works at subPath"+      it "works with subpath at the root of the file server" $ urlMapApp $ do+        req <- request (setRawPathInfo defRequest "/subPath")+        assertStatus 301 req+        assertHeader "Location" "/subPath/" req
wai-app-static.cabal view
@@ -1,5 +1,5 @@ name:            wai-app-static-version:         3.0.0.5+version:         3.0.0.6 license:         MIT license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>