poem-web / poem

A full-featured and easy-to-use web framework with the Rust programming language.
Apache License 2.0
3.62k stars 295 forks source link

Set multiple cookie headers in an OpenAPI route #895

Open musjj opened 1 month ago

musjj commented 1 month ago

Description of the feature

Current, if you try to set multiple Set-Cookie headers, only the last one is used:

struct Api;

#[derive(ApiResponse)]
pub enum FooResponse {
    #[oai(status = 200)]
    SetCookie(
        #[oai(header = "Set-Cookie")] String,
        #[oai(header = "Set-Cookie")] String,
    ),
}

#[OpenApi]
impl Api {
    #[oai(path = "/foo", method = "get")]
    pub async fn foo(&self) -> FooResponse {
        FooResponse::SetCookie("foo=1".into(), "bar=1".into())
    }
}
$ curl -I http://localhost:3000/foo
HTTP/1.1 200 OK
set-cookie: bar=1
date: Fri, 11 Oct 2024 16:21:35 GMT

This is a limitation of the current OpenAPI spec: https://github.com/OAI/OpenAPI-Specification/issues/1237.

But is there a way to work around this? Is there a way to set additional headers in the response object beyond what is annotated in the struct?