haskell-servant / haskell-servant/servant

Add Content-Length header

Open
#1,236 7 comments 0 reactions 0 assignees View on GitHub
bug enhancement
Dominant language
Haskell
Stars
2k
Forks
427
Avg merge
2d 23h
Merged PRs (30d)
5

Description

When using servant, none of the end-points return a "Content-Length" header. Instead, all of the response bodies are returned streaming.

Since servant endpoints generally always return a full object (JSON object, HTML object, etc...), I believe the size of the response is known, and the "Content-Length" header can be set.

The missing "Content-Length" header causes degraded performance when using [Network.Wai.Middleware.Gzip](https://hackage.haskell.org/package/wai-extra) middleware. This is because that middleware checks the "Content-Length" header in order to skip compression on small response bodies (less than 860 bytes). The source is here: and here is the reasoning:

Servant is typically used for JSON APIs, so many responses in real projects will be small JSON payloads (less than 860 bytes).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.