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

Zio-http does not send the correct Content-Type response header. #3284

Open
ffprivacy opened this issue Jan 25, 2025 · 0 comments
Open

Zio-http does not send the correct Content-Type response header. #3284

ffprivacy opened this issue Jan 25, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@ffprivacy
Copy link

Describe the bug
Zio-http does not send the correct Content-Type response header. When client send the Accept header to plain/text.

To Reproduce
Steps to reproduce the behaviour:

val mediaTypeJsonOrTextEndpoint = Endpoint(RoutePattern.POST / "api" / "mediaTypeJsonOrText")
        .outCodec(HttpCodec.content[Greeting](MediaType.text.plain))
        .outCodec(HttpCodec.content[Greeting](MediaType.application.json))
routes = routes :+ mediaTypeJsonOrTextEndpoint.implement {
    case (name) => {
        ZIO.succeed(new Greeting(name="greeting"))
    }
}
endpoints = endpoints :+ mediaTypeJsonOrTextEndpoint
var openAPI       = OpenAPIGen.fromEndpoints(title = "Server OpenAPI", version = "1.0", bookEndpoint, endpoints: _*)
val swaggerRoutes = SwaggerUI.routes("openapi", openAPI)
for(server <- openAPI.servers) {
    println(f"server=${server}")
}

routes = routes ++ swaggerRoutes.sandbox

val app = routes.sandbox

val run = Server.serve(app).provide(Server.default, Client.default).exitCode
  1. Select response type text/plain (set the Accept header) in the swagger ui in the mediaTypeJsonOrText path
  2. Click execute
  3. Response is still json, zio-http has not choosed the right codec

Expected behaviour
Changing the Accept header must cause the client to send Content-Type: plain/text as response and the body as this type

Screenshots
Image

Desktop (please complete the following information):

  • OS: ubuntu
  • Browser: brave
  • Version: Version 1.74.48 Chromium: 132.0.6834.83 (Build officiel) (64 bits)](https://brave.com/latest/)
@ffprivacy ffprivacy added the bug Something isn't working label Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant