]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: test-http-payload - Use ostream-final-trickle for server connections
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 11 Jan 2023 12:32:20 +0000 (14:32 +0200)
committerMarkus Valentin <markus.valentin@open-xchange.com>
Tue, 17 Jan 2023 11:10:41 +0000 (12:10 +0100)
src/lib-http/test-http-payload.c

index 690f465d34a57b7c969e5d9c5b05290f31f670a5..5cad093aa11dd3beadaf67be0b771ae429431f42 100644 (file)
@@ -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 <sys/types.h>
@@ -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)