From: Timo Sirainen Date: Thu, 12 Jan 2023 10:23:31 +0000 (+0200) Subject: lib-http: server - Don't disconnect client before response is fully sent X-Git-Tag: 2.3.21~121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e72869b16a53aded9d1754d28707f357b2e82675;p=thirdparty%2Fdovecot%2Fcore.git lib-http: server - Don't disconnect client before response is fully sent This could happen at least when the payload is empty and the final LF was buffered. --- diff --git a/src/lib-http/http-server-response.c b/src/lib-http/http-server-response.c index 280f2e6af2..21722f6293 100644 --- a/src/lib-http/http-server-response.c +++ b/src/lib-http/http-server-response.c @@ -357,6 +357,12 @@ int http_server_response_finish_payload_out(struct http_server_response *resp) o_stream_unref(&resp->payload_output); resp->payload_output = NULL; } + if (o_stream_get_buffer_used_size(conn->conn.output) > 0) { + e_debug(resp->event, + "Not quite finished sending response"); + conn->output_locked = TRUE; + return 0; + } e_debug(resp->event, "Finished sending payload"); @@ -504,13 +510,13 @@ int http_server_response_send_more(struct http_server_response *resp) struct ostream *output = resp->payload_output; enum ostream_send_istream_result res; - i_assert(resp->payload_output != NULL); - if (resp->payload_finished) { e_debug(resp->event, "Finish sending payload (more)"); return http_server_response_finish_payload_out(resp); } + i_assert(resp->payload_output != NULL); + if (resp->payload_stream != NULL) { conn->output_locked = TRUE; return http_server_ostream_continue(resp->payload_stream);