zio-http icon indicating copy to clipboard operation
zio-http copied to clipboard

Cannot use `Accept */*` header

Open swoogles opened this issue 1 year ago • 4 comments

Describe the bug K8s liveliness/readiness probes attach this header by default - Accept */*

Using the latest snapshot - 3.0.0-RC4+77-66867e7f-SNAPSHOT gives this error:

199 ZIO HTTP "... java.lang.IllegalArgumentException: None of the media types Chunk"

To Reproduce

object FailsOnAcceptWildcard extends ZIOAppDefault {

  val healthRoute =
    Endpoint(Method.GET / "health" / "api")
      .out[String]
      .implement {
        Handler.fromZIO(
          ZIO.succeed("API is healthy!")
        )
      }

  def run =
      Server
        .serve(healthRoute.toHttpApp)
        .provide(Server.default)
        .exitCode
      
}

Then execute:

curl -I -X 'GET' 'localhost:9007/health/api' -H 'accept: */*'

Expected behaviour Should return a 200. Users shouldn't need to change the default K8s probe behavior.

swoogles avatar Feb 23 '24 18:02 swoogles

I have the same ussue using Postman that adds this header by default.

brndt avatar Mar 11 '24 13:03 brndt

Curl adds this header by default as well.

allaryin avatar Mar 14 '24 20:03 allaryin

Setting my accept header forcibly to "application/json" does, in fact, make zio return correctly...

allaryin avatar Mar 14 '24 20:03 allaryin

Setting my accept header forcibly to "application/json" does, in fact, make zio return correctly...

Yep, you can work around it by providing different headers in whatever client you're using.

But 3 major tools:

  • Kubernetes
  • Postman
  • Curl (And I'm sure there are others)

All send a default header value that breaks zio-http. A web server can't realistically demand that all of these tools change their behavior in order to work together.

swoogles avatar Mar 15 '24 17:03 swoogles