pandoc-server.cgi: allow setting timeout

via PANDOC_SERVER_TIMEOUT environment variable.
This commit is contained in:
John MacFarlane 2022-08-18 22:33:19 -07:00
parent 5092292217
commit d3aa51b1ee
3 changed files with 9 additions and 3 deletions

View file

@ -15,7 +15,8 @@ import qualified Control.Exception as E
import Text.Pandoc.App (convertWithOpts, defaultOpts, options, parseOptions)
import Text.Pandoc.Error (handleError)
import Text.Pandoc.Server (ServerOpts(..), parseServerOpts, app)
import System.Environment (getProgName)
import Safe (readDef)
import System.Environment (getProgName, lookupEnv)
import qualified Network.Wai.Handler.CGI as CGI
import qualified Network.Wai.Handler.Warp as Warp
import Network.Wai.Middleware.Timeout (timeout)
@ -23,8 +24,9 @@ import Network.Wai.Middleware.Timeout (timeout)
main :: IO ()
main = E.handle (handleError . Left) $ do
prg <- getProgName
cgiTimeout <- maybe 2 (readDef 2) <$> lookupEnv "PANDOC_SERVER_TIMEOUT"
case prg of
"pandoc-server.cgi" -> CGI.run (timeout 2 app)
"pandoc-server.cgi" -> CGI.run (timeout cgiTimeout app)
"pandoc-server" -> do
sopts <- parseServerOpts
Warp.run (serverPort sopts) (timeout (serverTimeout sopts) app)

View file

@ -42,6 +42,9 @@ does, however, impose certain limitations:
`--timeout SECONDS`
: Timeout in seconds, after which a conversion is killed. Default: 2.
When `pandoc-server` is run as a CGI program, this option
can be set via the `PANDOC_SERVER_TIMEOUT` environment variable.
`--help`
: Print this help.

View file

@ -790,7 +790,8 @@ executable pandoc
buildable: True
other-modules: Paths_pandoc
build-depends: wai-extra >= 3.0.24,
warp
warp,
safe
test-suite test-pandoc
import: common-executable