Tapir zio-http routing via header

My team is trying to disambiguate between v1 and v2 of an api we’re developing by changing a “version” header from 1 to 2 while keeping the same url, but we haven’t been able to get it to work.

I had hoped that I could add something like .in(header("Version", "2")) to the endpoint declaration, but we put the v1 and v2 endpoints into a list for ZioHttpInterpreter.toHttp(endpoints), whichever endpoint is listed first takes all the traffic and then returns a decoder failure on traffic that should have gone to the other endpoint.

Does anyone know if tapir and zio-http even support this “pattern”, or are we out of luck?

The alternative is having one endpoint accept traffic for both version and delay decoding the different json bodies until the version header has been read. This seems to work, but the manual decoding is painful, especially in trying to match the existing error handling that tapir/zio-http would be handling for us.