From eb21f73fd36e325536f5e920be9dab3aa51581af Mon Sep 17 00:00:00 2001 From: hallgren Date: Wed, 9 Jan 2013 13:28:45 +0000 Subject: [PATCH] PGF service: new command: download This makes it possible to download PGF files from servers where the PGF service is installed. I am also considering making commmand=download the default instead of command=grammar. --- src/server/FastCGIUtils.hs | 14 +++++++++----- src/server/PGFService.hs | 7 ++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/server/FastCGIUtils.hs b/src/server/FastCGIUtils.hs index 2abc66072..05aa29eac 100644 --- a/src/server/FastCGIUtils.hs +++ b/src/server/FastCGIUtils.hs @@ -3,9 +3,8 @@ module FastCGIUtils (--initFastCGI, loopFastCGI, throwCGIError, handleCGIErrors, stderrToFile,logError, outputJSONP,outputEncodedJSONP, - outputPNG, - outputHTML, - outputPlain, + outputPNG,outputBinary, + outputHTML,outputPlain, splitBy) where import Control.Concurrent @@ -177,14 +176,19 @@ outputPNG x = do setHeader "Content-Type" "image/png" outputFPS x +outputBinary :: BS.ByteString -> CGI CGIResult +outputBinary x = do + setHeader "Content-Type" "application/binary" + outputFPS x + outputHTML :: String -> CGI CGIResult outputHTML x = do - setHeader "Content-Type" "text/html" + setHeader "Content-Type" "text/html; charset=utf-8" outputStrict $ UTF8.encodeString x outputPlain :: String -> CGI CGIResult outputPlain x = do - setHeader "Content-Type" "text/plain" + setHeader "Content-Type" "text/plain; charset=utf-8" outputStrict $ UTF8.encodeString x outputStrict :: String -> CGI CGIResult diff --git a/src/server/PGFService.hs b/src/server/PGFService.hs index ed19541f1..ee83394da 100644 --- a/src/server/PGFService.hs +++ b/src/server/PGFService.hs @@ -51,11 +51,12 @@ cgiMain' cache path = do pgf <- liftIO $ readCache cache path command <- liftM (maybe "grammar" (urlDecodeUnicode . UTF8.decodeString)) (getInput "command") - pgfMain pgf command + pgfMain path pgf command -pgfMain :: PGF -> String -> CGI CGIResult -pgfMain pgf command = +pgfMain :: FilePath -> PGF -> String -> CGI CGIResult +pgfMain path pgf command = case command of + "download" -> outputBinary =<< liftIO (BS.readFile path) "parse" -> outputJSONP =<< doParse pgf `fmap` getText `ap` getCat `ap` getFrom `ap` getLimit "complete" -> outputJSONP =<< doComplete pgf `fmap` getText `ap` getCat `ap` getFrom `ap` getLimit "linearize" -> outputJSONP =<< doLinearize pgf `fmap` getTree `ap` getTo