From: Timo Sirainen Date: Wed, 11 Jan 2023 12:32:20 +0000 (+0200) Subject: lib-http: test-http-payload - Use ostream-final-trickle for server connections X-Git-Tag: 2.3.21~117 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1414b26044f696c60b32b2ebbb2940ffa75fabd9;p=thirdparty%2Fdovecot%2Fcore.git lib-http: test-http-payload - Use ostream-final-trickle for server connections --- diff --git a/src/lib-http/test-http-payload.c b/src/lib-http/test-http-payload.c index 690f465d34..5cad093aa1 100644 --- a/src/lib-http/test-http-payload.c +++ b/src/lib-http/test-http-payload.c @@ -8,6 +8,7 @@ #include "ioloop.h" #include "istream.h" #include "ostream.h" +#include "ostream-final-trickle.h" #include "istream-crlf.h" #include "iostream-temp.h" #include "iostream-ssl.h" @@ -20,7 +21,7 @@ #include "test-subprocess.h" #include "http-url.h" #include "http-request.h" -#include "http-server.h" +#include "http-server-private.h" #include "http-client.h" #include @@ -62,6 +63,7 @@ static struct test_settings { enum payload_handling server_payload_handling; size_t read_server_partial; bool server_cork; + bool trickle_final_byte; bool ssl; } tset; @@ -329,7 +331,13 @@ client_handle_download_request(struct client_request *creq, o_stream_destroy(&output); } else { http_server_response_set_payload(resp, fstream); - http_server_response_submit(resp); + if (!tset.trickle_final_byte) + http_server_response_submit(resp); + else { + /* close connection immediately, so ostream-delay can + catch bugs with too early disconnects. */ + http_server_response_submit_close(resp); + } } i_stream_unref(&fstream); } @@ -855,6 +863,15 @@ static void client_accept(void *context ATTR_UNUSED) } } +static void test_http_server_connection_init(struct connection *conn) +{ + if (!tset.trickle_final_byte) + return; + struct ostream *output = o_stream_create_final_trickle(conn->output); + o_stream_unref(&conn->output); + conn->output = output; +} + /* */ static void test_server_init(const struct http_server_settings *server_set) @@ -863,6 +880,7 @@ static void test_server_init(const struct http_server_settings *server_set) io_listen = io_add(fd_listen, IO_READ, client_accept, NULL); http_server = http_server_init(server_set); + http_server->conn_list->v.init = test_http_server_connection_init; } static void test_server_deinit(void) @@ -1918,6 +1936,14 @@ static void test_download_server_nonblocking(void) test_run_pipeline(test_client_download); test_run_parallel(test_client_download); test_end(); + + test_begin("http payload download (server non-blocking; trickle final byte)"); + test_init_defaults(); + tset.trickle_final_byte = TRUE; + test_run_sequential(test_client_download); + test_run_pipeline(test_client_download); + test_run_parallel(test_client_download); + test_end(); } static void test_download_server_blocking(void)