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

servant-server returns errors that don't go through a formatter #1341

Open
neilmayhew opened this issue Sep 26, 2020 · 1 comment
Open

servant-server returns errors that don't go through a formatter #1341

neilmayhew opened this issue Sep 26, 2020 · 1 comment

Comments

@neilmayhew
Copy link

405 "Method Not Allowed" isn't formatted:

$ curl -v http://localhost:8080/post-endpoint
*   Trying ::1:8080...
* Connected to localhost (::1) port 8080 (#0)
> GET /post-endpoint HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.70.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 405 Method Not Allowed
< Transfer-Encoding: chunked
< Date: Sat, 26 Sep 2020 16:33:56 GMT
< Server: Warp/3.3.12
< 
* Connection #0 to host localhost left intact

404 "Not Found" is formatted:

$ curl -v http://localhost:8080/nonexistent-endpoint
*   Trying ::1:8080...
* Connected to localhost (::1) port 8080 (#0)
> GET /nonexistent-endpoint HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.70.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Transfer-Encoding: chunked
< Date: Sat, 26 Sep 2020 17:01:22 GMT
< Server: Warp/3.3.12
< Content-Type: application/json
< 
* Connection #0 to host localhost left intact
{"msg":"Not found path: /other-endpoint"}

You can see the various places where unformatted errors are returned in the code:

$ git grep -E 'Fail.*err[0-9]+' servant-server/src
servant-server/src/Servant/Server.hs:  routerLayout (route p context (emptyDelayed (FailFatal err501)))
servant-server/src/Servant/Server/Internal.hs:  | otherwise                    = delayedFail err405
servant-server/src/Servant/Server/Internal.hs:  | otherwise                   = delayedFail err406
servant-server/src/Servant/Server/Internal.hs:                 Nothing -> FailFatal err406 -- this should not happen (checked before), so we make it fatal if it does
servant-server/src/Servant/Server/Internal.hs:              accCheck = when (isNothing cmediatype) $ delayedFail err406
servant-server/src/Servant/Server/Internal.hs:          Nothing -> delayedFail err415
servant-server/src/Servant/Server/Internal/BasicAuth.hs:       Unauthorized   -> delayedFailFatal err403
servant-server/src/Servant/Server/Internal/BasicAuth.hs:  where plzAuthenticate = delayedFailFatal err401 { errHeaders = [mkBAChallengerHdr realm] }
@maksbotan
Copy link
Contributor

Hmm, as far as I understand HTTP spec, 404 and 405 responses are not expected to have a body anyway. Do you disagree?

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

2 participants