test-http-payload.c revision 641ab76d7defa171d2b558afcce2e1ac6e49d8b9
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2013-2016 Dovecot authors, see the included COPYING file */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainenstatic void test_files_read_dir(const char *path)
7bd72e4deca3cbf757dd1ea298486d9f3bc24226Timo Sirainen /* open the directory */
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen /* read entries */
b44650b0f48a4b5f0dc240ed836833a00b643b9fTimo Sirainen /* Close the directory */
b4f2560c29dacd066ba89e782d95ceed7ac473a3Timo Sirainenstatic void test_files_init(void)
1479a685cdb1641783ac02ba135450929f5c2658Timo Sirainen /* initialize file array */
b44650b0f48a4b5f0dc240ed836833a00b643b9fTimo Sirainen /* obtain all filenames */
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainenstatic void test_files_deinit(void)
ac713658d206e8d001fef7c0e36945793f2eb942Timo Sirainenstatic struct istream *
473080c7c0d25ddfdf77e7dfa0ba8f73c6c669d5Timo Sirainen unsigned int *status_r, const char **reason_r)
b24ffea8baa472d9b542e54ed3f9939eefd020adTimo Sirainen * Test server
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainenstatic const struct http_server_callbacks http_callbacks;
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen/* location: /succes */
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainenclient_handle_success_request(struct client_request *creq)
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen struct http_server_request *req = creq->server_req;
e48d89622047bd8bbd0475b881ca9377d592f535Timo Sirainen resp = http_server_response_create(req, 200, "OK");
8ff9812659728d4166df8e003a1dd3524ae8514eTimo Sirainen/* location: /download/... */
d5abbb932a0a598f002da39a8b3326643b1b5efcTimo Sirainen struct http_server_request *req = creq->server_req;
04052d7cacaa866a3f00afb4e104fa46c04c1dd7Timo Sirainen unsigned int status;
10f6f2224c897fc543973efd2f46b86a3ab1148dAki Tuomi fstream = test_file_open(fpath, &status, &reason);
268a76700330d159c805c70d1e3eae2e21f1cb9eAki Tuomi resp = http_server_response_create(req, 200, "OK");
268a76700330d159c805c70d1e3eae2e21f1cb9eAki Tuomi http_server_response_add_header(resp, "Content-Type", "text/plain");
268a76700330d159c805c70d1e3eae2e21f1cb9eAki Tuomi output = http_server_response_get_payload_output(resp, TRUE);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen while ((ret=o_stream_send_istream (output, fstream)) > 0);
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen "failed to send blocking file payload");
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen "finished sending blocking payload for %s"
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen http_server_response_set_payload(resp, fstream);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen/* location: /echo */
849969f639a00eab26791db3cb1b66430420c0cdTimo Sirainenclient_request_read_echo_more(struct client_request *creq)
9625595c47c665f5aee57ebfcb1fcbe9ad1bf3a0Martti Rannanjärvi o_stream_set_max_buffer_size(creq->payload_output, IO_BLOCK_SIZE);
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen ret = o_stream_send_istream(creq->payload_output, creq->payload_input);
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen o_stream_set_max_buffer_size(creq->payload_output, (size_t)-1);
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen if (creq->payload_output->stream_errno != 0) {
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen "Failed to write all echo payload [%s]", creq->path);
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen "Failed to read all echo payload [%s]", creq->path);
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen if (i_stream_have_bytes_left(creq->payload_input))
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen payload_input = iostream_temp_finish(&creq->payload_output, 4096);
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen http_server_response_add_header(resp, "Content-Type", "text/plain");
43a66a0b16299bd4f7615acd85e98bd3832c54d5Timo Sirainen http_server_response_set_payload(resp, payload_input);
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainenclient_handle_echo_request(struct client_request *creq,
2028d80c2704bbf62b29b2c624b0ee3c3a03c462Timo Sirainen struct http_server_request *req = creq->server_req;
9ed2951bd0bb1878a27437d7c00611b2baadd614Timo Sirainen (void)http_request_get_payload_size(hreq, &size);
("/tmp/test-http-server", 0);
if (blocking) {
if (read_partial > 0) {
if (ret < 0) {
if (debug) {
if (ret < 0) {
if (debug) {
if (read_partial > 0) {
static struct client_request *
return creq;
if (debug) {
int fd;
static void test_server_deinit(void)
struct test_client_request {
unsigned int files_idx;
static void test_client_download_continue(void);
const char **paths;
unsigned int count;
if (debug) {
if (ret == 0) {
if (debug) {
fsize = 0;
} else if (debug) {
const char **paths;
const char *path;
const char *reason;
if (debug) {
if (debug) {
if (debug) {
if (debug) {
static void test_client_download_continue(void)
const char *const *paths;
unsigned int count;
if (debug) {
client_files_last++) {
if (debug) {
static void test_client_echo_continue(void);
const char **paths;
unsigned int count;
if (debug) {
if (ret == 0) {
if (debug) {
fsize = 0;
} else if (debug) {
const char **paths;
const char *path;
if (debug) {
if (debug) {
if (read_partial > 0) {
if (debug) {
static void test_client_echo_continue(void)
const char **paths;
unsigned int count;
if (debug) {
client_files_last++) {
if (debug) {
if (debug) {
static void test_client_deinit(void)
static void test_open_server_fd(void)
static void test_run_client_server(
int status;
if (pid == 0) {
hostpid_init();
if (debug)
if (debug)
static void test_run_sequential(
static void test_run_pipeline(
static void test_run_parallel(
static void test_download_server_nonblocking(void)
read_partial = 0;
test_end();
static void test_download_server_blocking(void)
read_partial = 0;
test_end();
static void test_echo_server_nonblocking(void)
read_partial = 0;
test_end();
static void test_echo_server_blocking(void)
read_partial = 0;
test_end();
static void test_echo_server_nonblocking_sync(void)
read_partial = 0;
test_end();
static void test_echo_server_blocking_sync(void)
read_partial = 0;
test_end();
static void test_echo_server_nonblocking_partial(void)
test_end();
test_end();
static void test_echo_server_blocking_partial(void)
test_end();
test_end();
static void (*test_functions[])(void) = {
int main(void)