Log request and exceptions for handlers that use `escapeHttp` and `terminateConnection`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the Snap HTTP server handling paths through escapeHttp and terminateConnection, using the minimal SnapTest.hs example and its runhaskell/curl commands to reproduce the missing logs. Done means requests through both handlers log the requested path and exceptions from handlers are logged.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Haskell
- Stars
- 197
- Forks
- 87
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from snapframework/snap-server
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
snapframework/snap-server#118 · 5 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
snapframework/snap-server#96 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
snapframework/snap-server#92 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
snapframework/snap-server#85 · 8 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
snapframework/snap-server#77 · 2 comments ·
All issues in snapframework/snap-server
Similar issues
-
chore
Difficulty 1/5 Under an hour Newbie friendliness 91/100
alunduil/alunduil-chezmoi#792 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
haskellfoundation/haskellfoundation.github.io#637 · 2 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
koalaman/shellcheck#3539 ·
-
time-manager-0.4.0 Openfailure: bounds
Difficulty 1/5 Under an hour Newbie friendliness 72/100
commercialhaskell/stackage#8122 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
objectionary/phino#1350 ·