bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
38af46387e565053adf6c47f7f6871676d685de8Stephan Boschstatic enum payload_handling server_payload_handling =
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void test_files_read_dir(const char *path)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* open the directory */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* read entries */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* Close the directory */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* initialize file array */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* obtain all filenames */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic struct istream *
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch unsigned int *status_r, const char **reason_r)
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi return i_stream_create_fd_autoclose(&fd, 40960);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch * Test server
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic const struct http_server_callbacks http_callbacks;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch/* location: /succes */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschclient_handle_success_request(struct client_request *creq)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch struct http_server_request *req = creq->server_req;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch resp = http_server_response_create(req, 200, "OK");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch/* location: /download/... */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch struct http_server_request *req = creq->server_req;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch fstream = test_file_open(fpath, &status, &reason);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_request_fail(req, status, reason);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch resp = http_server_response_create(req, 200, "OK");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_response_add_header(resp, "Content-Type", "text/plain");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch output = http_server_response_get_payload_output(resp, TRUE);
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen if (o_stream_send_istream(output, fstream) != OSTREAM_SEND_ISTREAM_RESULT_FINISHED) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "failed to send blocking file payload");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "finished sending blocking payload for %s"
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_response_set_payload(resp, fstream);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch/* location: /echo */
38af46387e565053adf6c47f7f6871676d685de8Stephan Boschclient_request_finish_payload_in(struct client_request *creq)
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch payload_input = iostream_temp_finish(&creq->payload_output, 4096);
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch http_server_response_add_header(resp, "Content-Type", "text/plain");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch http_server_response_set_payload(resp, payload_input);
38af46387e565053adf6c47f7f6871676d685de8Stephan Boschclient_request_read_echo(struct client_request *creq)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch o_stream_set_max_buffer_size(creq->payload_output, IO_BLOCK_SIZE);
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen res = o_stream_send_istream(creq->payload_output, creq->payload_input);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch o_stream_set_max_buffer_size(creq->payload_output, (size_t)-1);
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen "Failed to read all echo payload [%s]", creq->path);
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT:
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen "Failed to write all echo payload [%s]", creq->path);
38af46387e565053adf6c47f7f6871676d685de8Stephan Boschclient_request_read_echo_more(struct client_request *creq)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "finished receiving payload for %s", creq->path);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschclient_handle_echo_request(struct client_request *creq,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch struct http_server_request *req = creq->server_req;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch (void)http_request_get_payload_size(hreq, &size);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_response_add_header(resp, "Content-Type", "text/plain");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_request_get_payload_input(req, TRUE);
ca270e31c9c43f7559b2378cb3ece7e09491e4d9Stephan Bosch i_stream_create_limit(payload_input, read_server_partial);
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen if (o_stream_send_istream(payload_output, payload_input) != OSTREAM_SEND_ISTREAM_RESULT_FINISHED) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "failed to receive blocking echo payload");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch payload_input = iostream_temp_finish(&payload_output, 4096);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "finished receiving blocking payload for %s", path);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch resp = http_server_response_create(req, 200, "OK");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_response_add_header(resp, "Content-Type", "text/plain");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch payload_output = http_server_response_get_payload_output(resp, TRUE);
378e6cb162b355d6f103526505bc00b9a78962e7Timo Sirainen if (o_stream_send_istream(payload_output, payload_input) != OSTREAM_SEND_ISTREAM_RESULT_FINISHED) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "failed to send blocking echo payload");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "finished sending blocking payload for %s", path);
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch http_server_request_get_payload_input(req, FALSE);
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch i_stream_create_limit(creq->payload_input, read_server_partial);
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch creq->io = io_add_istream(creq->payload_input,
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch http_server_request_get_payload_input(req, FALSE);
5a6d4adbdc10734f9e7abe90690609ffaa30199bAki Tuomihttp_server_request_destroyed(struct client_request *creq);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch pool_t pool = http_server_request_get_pool(req);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void client_request_deinit(struct client_request **_creq)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch struct http_server_request *req = creq->server_req;
5a6d4adbdc10734f9e7abe90690609ffaa30199bAki Tuomihttp_server_request_destroyed(struct client_request *creq)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch const char *path = hreq->target.url->path, *p;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch struct client *client = (struct client *)context;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "request method=`%s' path=`%s'", hreq->method, path);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_request_fail(req, 404, "Not found");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch if (strncmp(path, "/download", p-path) == 0) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_request_fail(req, 404, "Not found");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch/* client connection */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschclient_connection_destroy(void *context, const char *reason);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic const struct http_server_callbacks http_callbacks = {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch .connection_destroy = client_connection_destroy,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch client->http_conn = http_server_connection_create(http_server,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void client_deinit(struct client **_client)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_connection_close(&client->http_conn, "deinit");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschclient_connection_destroy(void *context, const char *reason ATTR_UNUSED)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void client_accept(void *context ATTR_UNUSED)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* accept new client */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschtest_server_init(const struct http_server_settings *server_set)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* open server socket */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* close server socket */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* deinitialize */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch * Test client
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Boschstatic struct test_client_request *client_requests;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic unsigned int client_files_first, client_files_last;
8b65acb3893f124707c0f64b5ef55a5a1e0fbd02Aki Tuomitest_client_request_destroy(struct test_client_request *tcreq)
20138b8f1e35113c6f1731abd489a290b8600eedStephan Bosch to_client_progress = io_loop_move_timeout(&to_client_progress);
20138b8f1e35113c6f1731abd489a290b8600eedStephan Boschtest_client_progress_timeout(void *context ATTR_UNUSED)
20138b8f1e35113c6f1731abd489a290b8600eedStephan Bosch /* Terminate test due to lack of progress */
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Boschtest_client_create_clients(const struct http_client_settings *client_set)
711f19747daffe980397ebf5acc3afb882816b7fStephan Bosch struct http_client_context *http_context = NULL;
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch unsigned int i;
20138b8f1e35113c6f1731abd489a290b8600eedStephan Bosch to_client_progress = timeout_add(CLIENT_PROGRESS_TIMEOUT*1000,
47baf5f9fe9a0bc50cdd74ab13c34489cc15a557Stephan Bosch http_context = http_client_context_create(client_set);
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch http_clients = i_new(struct http_client *, parallel_clients);
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch for (i = 0; i < parallel_clients; i++) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch/* download */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void test_client_download_continue(void);
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Boschtest_client_download_finished(unsigned int files_idx)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschtest_client_download_payload_input(struct test_client_request *tcreq)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* read payload */
651f981ca065d2365bf2ea07b04318a5402f047aTimo Sirainen while ((ret=i_stream_read_more(payload, &pdata, &psize)) > 0) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "got data for [%u] (size=%d)",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* compare with file on disk */
651f981ca065d2365bf2ea07b04318a5402f047aTimo Sirainen (tcreq->file, &fdata, &fsize)) > 0 && pleft > 0) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "received data does not match file "
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch if (ret < 0 && tcreq->file->stream_errno != 0) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "failed to read file: %s", i_stream_get_error(tcreq->file));
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "need more data for [%u]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* we will be called again for this request */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "failed to read request payload: %s",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch } if (i_stream_have_bytes_left(tcreq->file)) {
651f981ca065d2365bf2ea07b04318a5402f047aTimo Sirainen if (i_stream_read_more(tcreq->file, &fdata, &fsize) <= 0)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "payload ended prematurely "
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "(at least %"PRIuSIZE_T" bytes left)", fsize);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch } else if (debug) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "finished request for [%u]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* dereference payload stream; finishes the request */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch io_remove(&tcreq->io); /* holds a reference too */
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch /* finished */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschtest_client_download_response(const struct http_response *resp,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "got response for [%u]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "path for [%u]: %s",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch fstream = test_file_open(path, &status, &reason);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "got wrong response for %s: %u %s (expected: %u %s)",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch path, resp->status, resp->reason, status, reason);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "HTTP request for %s failed: %u %s",
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch test_client_download_finished(tcreq->files_idx);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "no payload for %s [%u]",
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch test_client_download_finished(tcreq->files_idx);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void test_client_download_continue(void)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch i_assert(client_files_first <= client_files_last);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch for (; client_files_first < client_files_last &&
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch paths[client_files_first] == NULL; client_files_first++)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "received until [%u]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch (client_files_last - client_files_first) < test_max_pending;
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch http_clients[client_files_last % parallel_clients];
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "retrieving %s [%u]",
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch hreq = tcreq->hreq = http_client_request(http_client,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_client_request_set_port(hreq, bind_port);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_client_request_set_destroy_callback(hreq,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschtest_client_download(const struct http_client_settings *client_set)
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch /* create client(s) */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* start querying server */
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Boschtest_client_echo_finished(unsigned int files_idx)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschtest_client_echo_payload_input(struct test_client_request *tcreq)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* read payload */
651f981ca065d2365bf2ea07b04318a5402f047aTimo Sirainen while ((ret=i_stream_read_more(payload, &pdata, &psize)) > 0) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "got data for [%u] (size=%d)",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* compare with file on disk */
651f981ca065d2365bf2ea07b04318a5402f047aTimo Sirainen (tcreq->file, &fdata, &fsize)) > 0 && pleft > 0) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "received data does not match file "
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch if (ret < 0 && tcreq->file->stream_errno != 0) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "failed to read file: %s", i_stream_get_error(tcreq->file));
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "need more data for [%u]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* we will be called again for this request */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "failed to read request payload: %s",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch } if (i_stream_have_bytes_left(tcreq->file)) {
651f981ca065d2365bf2ea07b04318a5402f047aTimo Sirainen if (i_stream_read_more(tcreq->file, &fdata, &fsize) <= 0)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "payload ended prematurely "
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "(at least %"PRIuSIZE_T" bytes left)", fsize);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch } else if (debug) {
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "finished request for [%u]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* dereference payload stream; finishes the request */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch io_remove(&tcreq->io); /* holds a reference too */
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch /* finished */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschtest_client_echo_response(const struct http_response *resp,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "got response for [%u]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "path for [%u]: %s",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "HTTP request for %s failed: %u %s",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch fstream = test_file_open(path, &status, NULL);
ca270e31c9c43f7559b2378cb3ece7e09491e4d9Stephan Bosch struct istream *partial = i_stream_create_limit
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch // FIXME: check file is empty
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "no payload for %s [%u]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch i_assert(client_files_first <= client_files_last);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch for (; client_files_first < client_files_last &&
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch paths[client_files_first] == NULL; client_files_first++);
641ab76d7defa171d2b558afcce2e1ac6e49d8b9Stephan Bosch "received until [%u/%u]", client_files_first-1, count);
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch "next blocking: %s [%d]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch (client_files_last - client_files_first) < test_max_pending;
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch http_clients[client_files_last % parallel_clients];
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "skipping %s [%u]",
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch "retrieving %s [%u]",
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch hreq = tcreq->hreq = http_client_request(http_client,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_client_request_set_port(hreq, bind_port);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_client_request_set_destroy_callback(hreq,
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch /* run nested ioloop (if requested) if new requests cross a nesting
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch unsigned int i;
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch for (i = ioloop_nested_first; i < ioloop_nested_last; i++) {
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch "not leaving ioloop [%u]", i);
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch } else if (client_ioloop_nesting > 0 &&
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch ((client_files_last / client_ioloop_nesting) !=
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch (first_submitted / client_ioloop_nesting)) ) {
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch unsigned int i;
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch ioloop_nested_last = first_submitted + client_ioloop_nesting;
19f8621e1473269d6820988d84f815774c2c1053Stephan Bosch i_debug("test client: echo: entering ioloop for %u...%u (depth=%u)",
19f8621e1473269d6820988d84f815774c2c1053Stephan Bosch ioloop_nested_first, ioloop_nested_last, ioloop_nested_depth);
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch for (i = 0; i < parallel_clients; i++)
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch for (i = 0; i < parallel_clients; i++)
19f8621e1473269d6820988d84f815774c2c1053Stephan Bosch i_debug("test client: echo: leaving ioloop for %u...%u (depth=%u)",
19f8621e1473269d6820988d84f815774c2c1053Stephan Bosch ioloop_nested_first, ioloop_nested_last, ioloop_nested_depth);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschtest_client_echo(const struct http_client_settings *client_set)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* create client */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* start querying server */
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch unsigned int i;
58e3ba77673e6069a366dbe96d3467dcaacc54feStephan Bosch for (i = 0; i < parallel_clients; i++)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch fd_listen = net_listen(&bind_ip, &bind_port, 128);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch const struct http_client_settings *client_set,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch const struct http_server_settings *server_set,
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch void (*client_init)(const struct http_client_settings *client_set))
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* child: server */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* parent: client */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch void (*client_init)(const struct http_client_settings *client_set))
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* download files from blocking server */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* server settings */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_set.request_limits.max_payload_size = (uoff_t)-1;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* client settings */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch (&http_client_set, &http_server_set, client_init);
20138b8f1e35113c6f1731abd489a290b8600eedStephan Bosch test_out_reason("sequential", (failure == NULL), failure);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch void (*client_init)(const struct http_client_settings *client_set))
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* download files from blocking server */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* server settings */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_set.request_limits.max_payload_size = (uoff_t)-1;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* client settings */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch (&http_client_set, &http_server_set, client_init);
20138b8f1e35113c6f1731abd489a290b8600eedStephan Bosch test_out_reason("pipeline", (failure == NULL), failure);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch void (*client_init)(const struct http_client_settings *client_set))
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* download files from blocking server */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* server settings */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_server_set.request_limits.max_payload_size = (uoff_t)-1;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* client settings */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch http_client_set.max_parallel_connections = 40;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch (&http_client_set, &http_server_set, client_init);
20138b8f1e35113c6f1731abd489a290b8600eedStephan Bosch test_out_reason("parallel", (failure == NULL), failure);
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void test_download_server_nonblocking(void)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch test_begin("http payload download (server non-blocking)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void test_download_server_blocking(void)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch test_begin("http payload download (server blocking)");
641ab76d7defa171d2b558afcce2e1ac6e49d8b9Stephan Bosch test_begin("http payload echo (server non-blocking)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch test_begin("http payload echo (server non-blocking; low-level)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_LOW_LEVEL;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch test_begin("http payload echo (server non-blocking; handler)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_HANDLER;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch test_begin("http payload echo (server blocking)");
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void test_echo_server_nonblocking_sync(void)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch test_begin("http payload echo (server non-blocking; 100-continue)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch test_begin("http payload echo (server non-blocking; 100-continue; low-level)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_LOW_LEVEL;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch test_begin("http payload echo (server non-blocking; 100-continue; handler)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_HANDLER;
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Boschstatic void test_echo_server_blocking_sync(void)
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch test_begin("http payload echo (server blocking; 100-continue)");
641ab76d7defa171d2b558afcce2e1ac6e49d8b9Stephan Boschstatic void test_echo_server_nonblocking_partial(void)
641ab76d7defa171d2b558afcce2e1ac6e49d8b9Stephan Bosch test_begin("http payload echo (server non-blocking; partial short)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
641ab76d7defa171d2b558afcce2e1ac6e49d8b9Stephan Bosch test_begin("http payload echo (server non-blocking; partial long)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch test_begin("http payload echo (server non-blocking; partial short; low-level)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_LOW_LEVEL;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch test_begin("http payload echo (server non-blocking; partial long; low-level)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch test_begin("http payload echo (server non-blocking; partial short; handler)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_HANDLER;
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch test_begin("http payload echo (server non-blocking; partial long; handler)");
641ab76d7defa171d2b558afcce2e1ac6e49d8b9Stephan Boschstatic void test_echo_server_blocking_partial(void)
641ab76d7defa171d2b558afcce2e1ac6e49d8b9Stephan Bosch test_begin("http payload echo (server blocking; partial short)");
641ab76d7defa171d2b558afcce2e1ac6e49d8b9Stephan Bosch test_begin("http payload echo (server blocking; partial long)");
ca270e31c9c43f7559b2378cb3ece7e09491e4d9Stephan Bosch test_begin("http payload download (client partial)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
ca270e31c9c43f7559b2378cb3ece7e09491e4d9Stephan Bosch test_begin("http payload download (client partial long)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Boschstatic void test_download_client_nested_ioloop(void)
b44c460e198dd3dd8be29304d4a3cb5e071894dcStephan Bosch test_begin("http payload echo (client nested ioloop)");
38af46387e565053adf6c47f7f6871676d685de8Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
b7f1ebf921c26dda1599cf03a6f4002f49edd057Stephan Bosch test_begin("http payload download (server non-blocking; client shared)");
5644698fc6d7d2e3b23188ebdaacf3b2c5e6bcebStephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
b7f1ebf921c26dda1599cf03a6f4002f49edd057Stephan Bosch test_begin("http payload download (server blocking; client shared)");
b7f1ebf921c26dda1599cf03a6f4002f49edd057Stephan Bosch test_begin("http payload echo (server non-blocking; client shared)");
b7f1ebf921c26dda1599cf03a6f4002f49edd057Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
b7f1ebf921c26dda1599cf03a6f4002f49edd057Stephan Bosch test_begin("http payload echo (server blocking; client shared)");
47baf5f9fe9a0bc50cdd74ab13c34489cc15a557Stephan Bosch test_begin("http payload echo (server non-blocking; client global)");
47baf5f9fe9a0bc50cdd74ab13c34489cc15a557Stephan Bosch server_payload_handling = PAYLOAD_HANDLING_FORWARD;
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainenstatic void (*const test_functions[])(void) = {
7362ba25c47c19e2dd9e61f066b487fa1f204c8aStephan Bosch /* make sure we don't leave any pesky children alive */
d5cdf90f01fe1b5a5e049f341398b2ee329b4de5Stephan Bosch /* listen on localhost */