]> gitweb @ CieloNegro.org - Rakka.git/commitdiff
Fixed canonicalization bug
authorpho <pho@cielonegro.org>
Fri, 22 Feb 2008 13:33:52 +0000 (22:33 +0900)
committerpho <pho@cielonegro.org>
Fri, 22 Feb 2008 13:33:52 +0000 (22:33 +0900)
darcs-hash:20080222133352-62b54-d093ba1700e9adcf13a1e81dfcfa70fe05388386.gz

Rakka/Resource.hs
Rakka/Resource/PageEntity.hs
Rakka/Resource/Search.hs
js/Makefile

index 5cbf188e46c8a468b16b5bdbfcbd5f1722f8d7c6..9f3af22fd6ef2752c0acdece23c4926177427bbc 100644 (file)
@@ -19,6 +19,7 @@ import           Network.URI hiding (path)
 import           Rakka.Authorization
 import           Rakka.Environment
 import           Rakka.Validation
+import           System.FilePath.Posix
 import           System.Log.Logger
 import           Text.XML.HXT.Arrow.ReadDocument
 import           Text.XML.HXT.Arrow.WriteDocument
@@ -36,27 +37,28 @@ logger = "Rakka.Resource"
 -- "/foo/"     ==> "/foo.html"
 -- "/foo.bar/" ==> "/foo.bar"
 -- "/foo.bar"  ==> "/foo.bar"
-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)
               $ abort MovedPermanently
                 [("Location", uriToString id newURI $ "")]
                 Nothing
 
 
-runIdempotentA :: IOSArrow () (Resource c) -> Resource c
-runIdempotentA a
-    = do canonicalizeURI
+runIdempotentA :: URI -> IOSArrow () (Resource c) -> Resource c
+runIdempotentA baseURI a
+    = do canonicalizeURI baseURI
          [rsrc] <- liftIO $ runX ( setErrorMsgHandler False fail
                                    >>>
                                    constA ()
index 8f4bd9caced4f263c09be86f1f02d6bfbcaf953c..e354004728c746caa043200d2c1ef9b336e39ec4 100644 (file)
@@ -55,19 +55,20 @@ fallbackPageEntity env path
 
 handleGet :: Environment -> PageName -> Resource ()
 handleGet env name
-    = runIdempotentA $ proc ()
-    -> do pageM <- getPageA (envStorage env) -< (name, Nothing)
-          case pageM of
-            Nothing
-                -> do items <- getDirContentsA (envStorage env) -< (name, Nothing)
-                      case items of
-                        [] -> handlePageNotFound   env -< name
-                        _  -> handleGetPageListing env -< (name, items)
-            Just page
-                -> if isEntity page then
-                       handleGetEntity env -< page
-                   else
-                       handleRedirect env -< page
+    = do BaseURI baseURI <- getSysConf (envSysConf env)
+         runIdempotentA baseURI $ proc ()
+             -> do pageM <- getPageA (envStorage env) -< (name, Nothing)
+                   case pageM of
+                     Nothing
+                         -> do items <- getDirContentsA (envStorage env) -< (name, Nothing)
+                               case items of
+                                 [] -> handlePageNotFound   env -< name
+                                 _  -> handleGetPageListing env -< (name, items)
+                     Just page
+                         -> if isEntity page then
+                                handleGetEntity env -< page
+                            else
+                                handleRedirect env -< page
 
 
 {-
index e4456e878387ef79e5bd414b1fe7c374bc4c8c7e..7c2acae6ad018f79619a7cc398c27a55d7fb0933 100644 (file)
@@ -77,7 +77,8 @@ handleSearch env
 
          let to' = min (from + length (srPages result)) to
 
-         runIdempotentA $ proc ()
+         BaseURI baseURI <- getSysConf (envSysConf env)
+         runIdempotentA baseURI $ proc ()
              -> do tree <- ( eelem "/"
                              += ( eelem "searchResult"
                                   += sattr "query" query
index f776451fba3bb46358fd28cb34dbc5811639dcf2..6db118db7acea0fd9eb4bfe5a436caae7908e773 100644 (file)
@@ -24,7 +24,7 @@ build: ../Rakka/Resource/JavaScript.hs
 
 packed.js: $(SOURCES) $(COMPRESSOR)
        cat $(SOURCES) > $@
-#      cat $(SOURCES) | $(COMPRESS) --warn -o $@
+#      cat $(SOURCES) | $(COMPRESS) -o $@
 
 
 ../Rakka/Resource/JavaScript.hs: packed.js