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

[actix-web][cookies] HttpResponse doesn't gererate any response. Cookies are not generted at all #509

Open
Piotr-Skorupa opened this issue Sep 15, 2023 · 4 comments

Comments

@Piotr-Skorupa
Copy link

Hi, I have noticed that only Json struct is able to generate resposne in final specification JSON. Unfortunately Json struct can not have cookies attached to it, so I need to use HttpResponse. I tried both actix_web::HttpResponse and paperclip::actix::web::HttpResponse. They don't generate anything. Here is what I am trying to achive:

#[api_v2_operation(
    description = "User authorization endpoint. Creates user session and returns auth cookies when credentials are correct",
    operation_id = "auth_handler",
    tags("Session", "Public API")
)]
#[post("/api/auth")]
pub async fn auth(
    params: Json<AuthUserRequest>,
    data: Data<Pool<ConnectionManager<PgConnection>>>,
    session: Session,
) -> actix_web::Result<HttpResponse> {
 
...

    let auth_cookie = actix_web::cookie::Cookie::build("user_uuid", found_user.uuid)
        .secure(true)
        .path("/")
        .finish();

    Ok(HttpResponse::Ok()
        .cookie(auth_cookie)
        .json(Json(())))
}

I have also similar issue with HttpRequest. Session cookies are atteched to it, but they are also not generated. Is there any way to generate them, even manually in api_v2_operation macro?

#[api_v2_operation(
    description = "User session verify endpoint. Returns OK when user session exists",
    operation_id = "session_verify_handler",
    tags("Session")
)]
#[get("/api/auth")]
pub async fn session_verify(reqest: HttpRequest, session: Session) -> actix_web::Result<Json<()>> {
    if User::authorize(&reqest, &session).is_some() {
        return Ok(Json(()));
    }

cookies are in -> request.cookie("name")

Best regards,
Piotr Skorupa

@tiagolobocastro
Copy link
Collaborator

hmm AFAIK there's no support for cookies, @wafflespeanut?

@wafflespeanut
Copy link
Collaborator

As far as I can recall, we walk through the types only once at the start and we can't infer anything useful from dynamic objects (like HttpResponse). Would be worth it to see how other packages are doing though.

@Piotr-Skorupa
Copy link
Author

Thanks, understood that dynamic objects are not supported, but what about cookies? Can I setup them manually in api_v2_operation macro?

@tiagolobocastro
Copy link
Collaborator

We don't have support for that at moment, but a PR would be welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants