Log request and exceptions for handlers that use `escapeHttp` and `terminateConnection`

Open
#94 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
haskell
Domain
api, backend

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from snapframework/snap-server

All issues in snapframework/snap-server

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.