Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log request and exceptions for handlers that use escapeHttp and terminateConnection #94

Open
HeinrichApfelmus opened this issue Dec 7, 2016 · 0 comments

Comments

@HeinrichApfelmus
Copy link

When using escapeHttp or terminateConnection to serve a request, the Snap HTTP server will not make any attempt to log the request, or any exception that the handler may throw.

I would prefer if Snap logs the requested path and any exception that the handler might throw. I found this useful in my Threepenny-GUI project. See also HeinrichApfelmus/threepenny-gui#145 .


Here is a minimal complete test case for the reported behavior:

$ cat SnapTest.hs
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8  as BS   (hPutStrLn)
import qualified Control.Exception      as E
import           Snap.Core              as Snap
import qualified Snap.Http.Server       as Snap
import           System.IO                      (stderr)

config = Snap.setErrorLog  (Snap.ConfigIoLog $ BS.hPutStrLn stderr)
       $ Snap.setAccessLog (Snap.ConfigIoLog $ BS.hPutStrLn stderr)
       $ Snap.defaultConfig

main = Snap.httpServe config $ route
  [ ("escape"   , Snap.escapeHttp $ \_ _ _ -> E.throw msg)
  , ("terminate", Snap.terminateConnection msg)]

msg = E.AssertionFailed "Hello?"

Request issued

$ curl http://0.0.0.0:8000
<!DOCTYPE html>
<html>
<head>
<title>Not found</title>
</head>
<body>
<code>No handler accepted "/"</code>
</body></html>
$ curl http://0.0.0.0:8000/escape

curl: (52) Empty reply from server
$ curl http://0.0.0.0:8000/terminate

curl: (52) Empty reply from server

and the corresponding log

$ runhaskell SnapTest.hs 
no port specified, defaulting to port 8000
Listening on http://0.0.0.0:8000
127.0.0.1 - - [07/Dec/2016:23:04:54 +0100] "GET / HTTP/1.1" 404 198 - "curl/7.30.0"

The second and third request have not generated any log entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant