]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: server - Don't disconnect client before response is fully sent
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 12 Jan 2023 10:23:31 +0000 (12:23 +0200)
committerMarkus Valentin <markus.valentin@open-xchange.com>
Tue, 17 Jan 2023 11:10:41 +0000 (12:10 +0100)
This could happen at least when the payload is empty and the final LF was
buffered.

src/lib-http/http-server-response.c

index 280f2e6af2347715d010e3c7586b9cfb78cdd42d..21722f6293d567df793fb300a91d9581170a0bde 100644 (file)
@@ -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);