-canonicalizeURI :: Resource ()
-canonicalizeURI
- = do uri <- getRequestURI
- let newURI = uri { uriPath = "/" ++ joinWith "/" newPath }
- newPath = case [x | x <- splitBy (== '/') (uriPath uri), x /= ""] of
- [] -> []
- path -> case break (== '.') $ last path of
- (_, "") -> let basePieces = reverse $ tail $ reverse path
- lastPiece = last path
- in
- basePieces ++ [lastPiece ++ ".html"]
- (_, _) -> path
- when (uri /= newURI)
+canonicalizeURI :: URI -> Resource ()
+canonicalizeURI baseURI
+ = do rPath <- return . uriPath =<< getRequestURI
+ let newURI = baseURI { uriPath = uriPath baseURI </> newPath }
+ newPath = foldl (</>) "/" newPath'
+ newPath' = case [x | x <- splitBy (== '/') rPath, x /= ""] of
+ [] -> []
+ path -> case break (== '.') $ last path of
+ (_, "") -> let basePieces = reverse $ tail $ reverse path
+ lastPiece = last path
+ in
+ basePieces ++ [lastPiece ++ ".html"]
+ (_, _) -> path
+ when (rPath /= newPath)