#509·paperclip

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

Author: Piotr-SkorupaCreated Sep 15, 2023Updated Oct 9, 2023

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