Skip to content

Commit

Permalink
refactoring pgfMain now takes the file path directly
Browse files Browse the repository at this point in the history
  • Loading branch information
krangelov committed May 16, 2024
1 parent 02e8dcb commit efe00f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/compiler/api/GF/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ handle logLn documentroot state0 cache execute stateVar conn = do
-- use/change the cwd. Access files by absolute paths only.
let path = translatePath rpath
in case (takeDirectory path,takeFileName path,takeExtension path) of
(_ ,_ ,".pgf") -> PS.pgfMain logLn conn cache [("PATH_TRANSLATED",path)] rq
(_ ,_ ,".ngf") -> PS.pgfMain logLn conn cache [("PATH_TRANSLATED",path)] rq
(_ ,_ ,".pgf") -> PS.pgfMain logLn conn cache path rq
(_ ,_ ,".ngf") -> PS.pgfMain logLn conn cache path rq
(dir,"grammars.cgi",_ ) -> addDate (grammarList dir query)
_ -> serveStaticFile conn rpath path
_ -> addDate (return $ resp400 upath)
Expand Down
7 changes: 2 additions & 5 deletions src/server/PGFService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import System.IO.Error(isDoesNotExistError)
import System.FilePath(takeExtension)
import System.Mem(performGC)
import Network.HTTP
import Network.FastCGI hiding (Connection, writeHeaders)
import Numeric(showHex)


Expand Down Expand Up @@ -62,8 +61,8 @@ newCache' root rd = do
clean c = do threadDelay 2000000000 -- 2000 seconds, i.e. ~33 minutes
expireCache (24*60*60) c -- 24 hours

pgfMain :: (String -> IO ()) -> Connection -> Caches -> Env -> Request -> IO ()
pgfMain logLn conn cache env rq =
pgfMain :: (String -> IO ()) -> Connection -> Caches -> FilePath -> Request -> IO ()
pgfMain logLn conn cache path rq =
case fromMaybe "grammar" (lookup "command" query) of
"download"
| ext == ".pgf" -> do tpgf <- getFile (readCache' (pgfCache cache)) path
Expand All @@ -77,8 +76,6 @@ pgfMain logLn conn cache env rq =
handleErrors logLn (pgfCommand (qsem cache) command query tpgf) >>= respondHTTP conn
_ -> respondHTTP conn (Response 415 "Bad Request" [] "Extension must be .pgf or .ngf")
where
path = fromMaybe "" (lookup "PATH_TRANSLATED" env `mplus`
lookup "SCRIPT_FILENAME" env)
ext = takeExtension path

query = rqQuery rq
Expand Down

0 comments on commit efe00f8

Please sign in to comment.