actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

Pending multipart request with angular rxjs

Open jonatansalemes opened this issue 1 year ago • 1 comments

i`m facing a very strange issue when i have multipart endpoints in actix using angular app (rxjs client):

actix endpoint

#[post("/mt")]
pub async fn service(payload: Multipart) -> Result<impl Responder, Error> {
    if true {
        let bad_request =
            HttpResponse::BadRequest().json(BadRequestError(BadRequestErrorResponse {
                message: "You don't have enough balance".to_string(),
            }));
        return Ok(bad_request);
    }

    Ok(HttpResponse::Ok().json("ss"))
}

angular http client request

    createNew(f1: File, f2: File) {
        const apiUrl = this.appConfig.apiUrl;
        const formData = new FormData();
        formData.set('f1', f1, f1.name);
        formData.set('f2', f2, f2.name);
        return this.httpClient
            .post<CreateNewSwapResponse>(`${apiUrl}/mt`, formData);
    }

after first bad request, the next request get in pending status forever in network tab.

i have switched to spring boot endpoint, that works nice without pending behaviour, to check headers difference. So spring after bad request send header

[only header, not closing server socket] Connection: close

actix does not sent nothing, after explore actix source code

image

i have, just for test, force connection close on encoder.rs even is keep alive was sent by client and stop hanging pending request in client after that. There is some way to add feature like force_close_header only ? because i have tryied force_close but this close socket generating error. Another idea maybe is respect if add_header(("Connection", "close")) was added instead use connection type to write connection header. Some idea ? i can write a pull request if need it.

jonatansalemes avatar Dec 12 '23 14:12 jonatansalemes

Got the same issue, thank you for your fixing, hope the PR be merged asap.

kvzn avatar Dec 25 '23 05:12 kvzn