haskell-servant / haskell-servant/servant

Why doesn't `Servant.Server.Internal.streamRouter` use `contentTypes`?

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

Description

So, I have a service that is basically a dumb pipe streaming data between two other (legacy) services. Said data can be in different formats and I'd like to use the Accept header to choose between them, using the following type:

```
data MagicStream

instance Accept MagicStream where
contentTypes _ = ["application/json", "text/csv"]

instance MimeRender MagicStream ByteString where
mimeRender _ = ByteString.Lazy.fromStrict
```

Then my API would look like this:

```
type Api = Header "Accept" ActualFormat :> ... :> StreamGet NoFraming MagicStream ...
```

Sadly, this is currently not possible and I have to invent my own `X-Magic-Accept` header to work around `streamRouter`'s use of `contentType` (only the first value in the `contentTypes` list is accepted).

Is that a concious design choice? I wouldn't be surprised if I'm missing something here.

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.