};
typedef void (*test_server_init_t)(unsigned int index);
-typedef bool (*test_client_init_t)
- (const struct http_client_settings *client_set);
+typedef bool
+(*test_client_init_t)(const struct http_client_settings *client_set);
typedef void (*test_dns_init_t)(void);
/*
/* server */
static void test_server_run(unsigned int index);
-static void
-server_connection_deinit(struct server_connection **_conn);
+static void server_connection_deinit(struct server_connection **_conn);
/* client */
-static void
-test_client_defaults(struct http_client_settings *http_set);
+static void test_client_defaults(struct http_client_settings *http_set);
static void test_client_deinit(void);
/* test*/
-static void test_run_client_server(
- const struct http_client_settings *client_set,
- test_client_init_t client_test,
- test_server_init_t server_test,
- unsigned int server_tests_count,
- test_dns_init_t dns_test)
- ATTR_NULL(3);
+static void
+test_run_client_server(const struct http_client_settings *client_set,
+ test_client_init_t client_test,
+ test_server_init_t server_test,
+ unsigned int server_tests_count,
+ test_dns_init_t dns_test) ATTR_NULL(3);
/*
* Unconfigured SSL
};
static void
-test_client_unconfigured_ssl_response(
- const struct http_response *resp,
- struct _unconfigured_ssl *ctx)
+test_client_unconfigured_ssl_response(const struct http_response *resp,
+ struct _unconfigured_ssl *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "127.0.0.1", "/unconfigured-ssl.txt",
+ hreq = http_client_request(
+ http_client, "GET", "127.0.0.1", "/unconfigured-ssl.txt",
test_client_unconfigured_ssl_response, ctx);
http_client_request_set_ssl(hreq, TRUE);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", "127.0.0.1", "/unconfigured-ssl2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "127.0.0.1", "/unconfigured-ssl2.txt",
test_client_unconfigured_ssl_response, ctx);
http_client_request_set_ssl(hreq, TRUE);
http_client_request_submit(hreq);
test_begin("unconfigured ssl");
test_run_client_server(&http_client_set,
- test_client_unconfigured_ssl,
- NULL, 0, NULL);
+ test_client_unconfigured_ssl, NULL, 0, NULL);
test_end();
}
static void
test_client_unconfigured_ssl_abort_response2(
- const struct http_response *resp,
- struct _unconfigured_ssl_abort *ctx)
+ const struct http_response *resp, struct _unconfigured_ssl_abort *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
}
static bool
-test_client_unconfigured_ssl_abort(const struct http_client_settings *client_set)
+test_client_unconfigured_ssl_abort(
+ const struct http_client_settings *client_set)
{
struct http_client_request *hreq;
struct _unconfigured_ssl_abort *ctx;
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "127.0.0.1", "/unconfigured-ssl.txt",
+ hreq = http_client_request(
+ http_client, "GET", "127.0.0.1", "/unconfigured-ssl.txt",
test_client_unconfigured_ssl_abort_response1, ctx);
http_client_request_set_ssl(hreq, TRUE);
http_client_request_submit(hreq);
http_client_request_abort(&hreq);
- hreq = http_client_request(http_client,
- "GET", "127.0.0.1", "/unconfigured-ssl2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "127.0.0.1", "/unconfigured-ssl2.txt",
test_client_unconfigured_ssl_abort_response2, ctx);
http_client_request_set_ssl(hreq, TRUE);
http_client_request_submit(hreq);
test_begin("unconfigured ssl abort");
test_run_client_server(&http_client_set,
- test_client_unconfigured_ssl_abort,
- NULL, 0, NULL);
+ test_client_unconfigured_ssl_abort,
+ NULL, 0, NULL);
test_end();
}
};
static void
-test_client_invalid_url_response(
- const struct http_response *resp,
- struct _invalid_url *ctx)
+test_client_invalid_url_response(const struct http_response *resp,
+ struct _invalid_url *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
http_client = http_client_init(client_set);
- hreq = http_client_request_url_str(http_client,
- "GET", "imap://example.com/INBOX",
+ hreq = http_client_request_url_str(
+ http_client, "GET", "imap://example.com/INBOX",
test_client_invalid_url_response, ctx);
http_client_request_submit(hreq);
- hreq = http_client_request_url_str(http_client,
- "GET", "http:/www.example.com",
+ hreq = http_client_request_url_str(
+ http_client, "GET", "http:/www.example.com",
test_client_invalid_url_response, ctx);
http_client_request_submit(hreq);
test_begin("invalid url");
test_run_client_server(&http_client_set,
- test_client_invalid_url,
- NULL, 0, NULL);
+ test_client_invalid_url, NULL, 0, NULL);
test_end();
}
};
static void
-test_client_host_lookup_failed_response(
- const struct http_response *resp,
- struct _host_lookup_failed *ctx)
+test_client_host_lookup_failed_response(const struct http_response *resp,
+ struct _host_lookup_failed *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
- test_assert(resp->status == HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
+ test_assert(resp->status ==
+ HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
test_assert(resp->reason != NULL && *resp->reason != '\0');
if (--ctx->count == 0) {
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "host.in-addr.arpa", "/host-lookup-failed.txt",
+ hreq = http_client_request(
+ http_client, "GET", "host.in-addr.arpa",
+ "/host-lookup-failed.txt",
test_client_host_lookup_failed_response, ctx);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", "host.in-addr.arpa", "/host-lookup-failed2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "host.in-addr.arpa",
+ "/host-lookup-failed2.txt",
test_client_host_lookup_failed_response, ctx);
http_client_request_submit(hreq);
test_begin("host lookup failed");
test_run_client_server(&http_client_set,
- test_client_host_lookup_failed,
- NULL, 0, NULL);
+ test_client_host_lookup_failed, NULL, 0, NULL);
test_end();
}
};
static void
-test_client_connection_refused_response(
- const struct http_response *resp,
- struct _connection_refused *ctx)
+test_client_connection_refused_response(const struct http_response *resp,
+ struct _connection_refused *ctx)
{
test_assert(ctx->to == NULL);
timeout_remove(&ctx->to);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-refused.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-refused.txt",
test_client_connection_refused_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-refused2.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-refused2.txt",
test_client_connection_refused_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("connection refused");
test_run_client_server(&http_client_set,
- test_client_connection_refused,
- test_server_connection_refused, 1,
- NULL);
+ test_client_connection_refused,
+ test_server_connection_refused, 1, NULL);
test_end();
http_client_set.max_connect_attempts = 3;
test_begin("connection refused backoff");
test_run_client_server(&http_client_set,
- test_client_connection_refused,
- test_server_connection_refused, 1,
- NULL);
+ test_client_connection_refused,
+ test_server_connection_refused, 1, NULL);
test_end();
}
server_connection_deinit(&conn);
}
-static void
-test_server_connection_lost_prematurely(unsigned int index)
+static void test_server_connection_lost_prematurely(unsigned int index)
{
test_server_input = test_server_connection_lost_prematurely_input;
test_server_run(index);
}
static bool
-test_client_connection_lost_prematurely(const struct http_client_settings *client_set)
+test_client_connection_lost_prematurely(
+ const struct http_client_settings *client_set)
{
struct http_client_request *hreq;
struct _connection_lost_prematurely *ctx;
ctx = i_new(struct _connection_lost_prematurely, 1);
ctx->count = 2;
- ctx->to = timeout_add_short(250,
- test_client_connection_lost_prematurely_timeout, ctx);
+ ctx->to = timeout_add_short(
+ 250, test_client_connection_lost_prematurely_timeout, ctx);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-refused-retry.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-refused-retry.txt",
test_client_connection_lost_prematurely_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-refused-retry2.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-refused-retry2.txt",
test_client_connection_lost_prematurely_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("connection lost prematurely");
test_run_client_server(&http_client_set,
- test_client_connection_lost_prematurely,
- test_server_connection_lost_prematurely, 1,
- NULL);
+ test_client_connection_lost_prematurely,
+ test_server_connection_lost_prematurely, 1,
+ NULL);
test_end();
}
};
static void
-test_client_connection_timed_out_response(
- const struct http_response *resp,
- struct _connection_timed_out *ctx)
+test_client_connection_timed_out_response(const struct http_response *resp,
+ struct _connection_timed_out *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
}
static bool
-test_client_connection_timed_out(
- const struct http_client_settings *client_set)
+test_client_connection_timed_out(const struct http_client_settings *client_set)
{
struct http_client_request *hreq;
struct _connection_timed_out *ctx;
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "192.168.0.0", "/connection-timed-out.txt",
+ hreq = http_client_request(
+ http_client, "GET", "192.168.0.0", "/connection-timed-out.txt",
test_client_connection_timed_out_response, ctx);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", "192.168.0.0", "/connection-timed-out2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "192.168.0.0", "/connection-timed-out2.txt",
test_client_connection_timed_out_response, ctx);
http_client_request_submit(hreq);
test_begin("connection timed out");
test_run_client_server(&http_client_set,
- test_client_connection_timed_out,
- NULL, 0, NULL);
+ test_client_connection_timed_out, NULL, 0, NULL);
test_end();
}
/* -> not accepted */
-static void
-test_invalid_redirect_input1(struct server_connection *conn)
+static void test_invalid_redirect_input1(struct server_connection *conn)
{
static const char *resp =
"HTTP/1.1 302 Redirect\r\n"
"Location: http://localhost:4444\r\n"
"\r\n";
+
o_stream_nsend_str(conn->conn.output, resp);
server_connection_deinit(&conn);
}
/* -> bad location */
-static void
-test_invalid_redirect_input2(struct server_connection *conn)
+static void test_invalid_redirect_input2(struct server_connection *conn)
{
static const char *resp =
"HTTP/1.1 302 Redirect\r\n"
"Location: unix:/var/run/dovecot/auth-master\r\n"
"\r\n";
+
o_stream_nsend_str(conn->conn.output, resp);
server_connection_deinit(&conn);
}
/* -> too many */
-static void
-test_invalid_redirect_input3(struct server_connection *conn)
+static void test_invalid_redirect_input3(struct server_connection *conn)
{
string_t *resp;
resp = t_str_new(512);
str_printfa(resp,
- "HTTP/1.1 302 Redirect\r\n"
- "Location: http://%s:%u/friep.txt\r\n"
- "\r\n",
- net_ip2addr(&bind_ip), bind_ports[server_index+1]);
- o_stream_nsend(conn->conn.output,
- str_data(resp), str_len(resp));
+ "HTTP/1.1 302 Redirect\r\n"
+ "Location: http://%s:%u/friep.txt\r\n"
+ "\r\n",
+ net_ip2addr(&bind_ip), bind_ports[server_index+1]);
+ o_stream_nsend(conn->conn.output, str_data(resp), str_len(resp));
server_connection_deinit(&conn);
}
/* client */
static void
-test_client_invalid_redirect_response(
- const struct http_response *resp,
- void *context ATTR_UNUSED)
+test_client_invalid_redirect_response(const struct http_response *resp,
+ void *context ATTR_UNUSED)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/invalid-redirect.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/invalid-redirect.txt",
test_client_invalid_redirect_response, NULL);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("invalid redirect: not accepted");
http_client_set.max_redirects = 0;
test_run_client_server(&http_client_set,
- test_client_invalid_redirect,
- test_server_invalid_redirect1, 1,
- NULL);
+ test_client_invalid_redirect,
+ test_server_invalid_redirect1, 1, NULL);
test_end();
test_begin("invalid redirect: bad location");
http_client_set.max_redirects = 1;
test_run_client_server(&http_client_set,
- test_client_invalid_redirect,
- test_server_invalid_redirect2, 1,
- NULL);
+ test_client_invalid_redirect,
+ test_server_invalid_redirect2, 1, NULL);
test_end();
test_begin("invalid redirect: too many");
http_client_set.max_redirects = 1;
test_run_client_server(&http_client_set,
- test_client_invalid_redirect,
- test_server_invalid_redirect3, 3,
- NULL);
+ test_client_invalid_redirect,
+ test_server_invalid_redirect3, 3, NULL);
test_end();
}
/* server */
-static void
-test_unseekable_redirect_input(struct server_connection *conn)
+static void test_unseekable_redirect_input(struct server_connection *conn)
{
string_t *resp;
resp = t_str_new(512);
str_printfa(resp,
- "HTTP/1.1 302 Redirect\r\n"
- "Location: http://%s:%u/frml.txt\r\n"
- "\r\n",
- net_ip2addr(&bind_ip), bind_ports[server_index+1]);
- o_stream_nsend(conn->conn.output,
- str_data(resp), str_len(resp));
+ "HTTP/1.1 302 Redirect\r\n"
+ "Location: http://%s:%u/frml.txt\r\n"
+ "\r\n",
+ net_ip2addr(&bind_ip), bind_ports[server_index+1]);
+ o_stream_nsend(conn->conn.output, str_data(resp), str_len(resp));
server_connection_deinit(&conn);
}
/* client */
static void
-test_client_unseekable_redirect_response(
- const struct http_response *resp,
- void *context ATTR_UNUSED)
+test_client_unseekable_redirect_response(const struct http_response *resp,
+ void *context ATTR_UNUSED)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
input = i_stream_create_from_data("FROP", 4);
input->seekable = FALSE;
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/unseekable-redirect.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/unseekable-redirect.txt",
test_client_unseekable_redirect_response, NULL);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_payload(hreq, input, FALSE);
test_begin("unseekable redirect");
test_run_client_server(&http_client_set,
- test_client_unseekable_redirect,
- test_server_unseekable_redirect, 2,
- NULL);
+ test_client_unseekable_redirect,
+ test_server_unseekable_redirect, 2, NULL);
test_end();
}
/* server */
-static void
-test_unseekable_retry_input(struct server_connection *conn)
+static void test_unseekable_retry_input(struct server_connection *conn)
{
server_connection_deinit(&conn);
}
/* client */
static void
-test_client_unseekable_retry_response(
- const struct http_response *resp,
- void *context ATTR_UNUSED)
+test_client_unseekable_retry_response(const struct http_response *resp,
+ void *context ATTR_UNUSED)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
input = i_stream_create_from_data("FROP", 4);
input->seekable = FALSE;
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/unseekable-retry.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/unseekable-retry.txt",
test_client_unseekable_retry_response, NULL);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_payload(hreq, input, FALSE);
test_begin("unseekable retry");
test_run_client_server(&http_client_set,
- test_client_unseekable_retry,
- test_server_unseekable_retry, 2,
- NULL);
+ test_client_unseekable_retry,
+ test_server_unseekable_retry, 2, NULL);
test_end();
}
/* server */
-static void
-test_broken_payload_input(struct server_connection *conn)
+static void test_broken_payload_input(struct server_connection *conn)
{
static const char *resp =
"HTTP/1.1 200 OK\r\n"
"Content-Length: 18\r\n"
"\r\n"
"Everything is OK\r\n";
+
o_stream_nsend_str(conn->conn.output, resp);
server_connection_deinit(&conn);
}
/* client */
static void
-test_client_broken_payload_response(
- const struct http_response *resp,
- void *context ATTR_UNUSED)
+test_client_broken_payload_response(const struct http_response *resp,
+ void *context ATTR_UNUSED)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
input = i_stream_create_error_str(EIO, "Moehahahaha!!");
i_stream_set_name(input, "PURE EVIL");
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/broken-payload.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/broken-payload.txt",
test_client_broken_payload_response, NULL);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_payload(hreq, input, FALSE);
test_begin("broken payload");
test_run_client_server(&http_client_set,
- test_client_broken_payload,
- test_server_broken_payload, 1,
- NULL);
+ test_client_broken_payload,
+ test_server_broken_payload, 1, NULL);
test_end();
}
/* server */
-static void
-test_connection_lost_input(struct server_connection *conn)
+static void test_connection_lost_input(struct server_connection *conn)
{
ssize_t ret;
};
static void
-test_client_connection_lost_response(
- const struct http_response *resp,
- struct _connection_lost_request_ctx *rctx)
+test_client_connection_lost_response(const struct http_response *resp,
+ struct _connection_lost_request_ctx *rctx)
{
struct _connection_lost_ctx *ctx = rctx->ctx;
test_client_connection_lost(const struct http_client_settings *client_set)
{
static const char payload[] =
- "This is a useless payload that only serves as a means to give the "
- "server the opportunity to close the connection before the payload "
- "is finished.";
+ "This is a useless payload that only serves as a means to give "
+ "the server the opportunity to close the connection before the "
+ "payload is finished.";
struct _connection_lost_ctx *ctx;
struct _connection_lost_request_ctx *rctx;
struct http_client_request *hreq;
rctx = i_new(struct _connection_lost_request_ctx, 1);
rctx->ctx = ctx;
- rctx->req = hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-lost.txt",
+ rctx->req = hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-lost.txt",
test_client_connection_lost_response, rctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_payload(hreq, input, FALSE);
rctx = i_new(struct _connection_lost_request_ctx, 1);
rctx->ctx = ctx;
- rctx->req = hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-lost2.txt",
+ rctx->req = hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-lost2.txt",
test_client_connection_lost_response, rctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("connection lost: one attempt");
http_client_set.max_attempts = 1;
test_run_client_server(&http_client_set,
- test_client_connection_lost,
- test_server_connection_lost, 1,
- NULL);
+ test_client_connection_lost,
+ test_server_connection_lost, 1, NULL);
test_end();
test_begin("connection lost: two attempts");
http_client_set.max_attempts = 2;
test_run_client_server(&http_client_set,
- test_client_connection_lost,
- test_server_connection_lost, 1,
- NULL);
+ test_client_connection_lost,
+ test_server_connection_lost, 1, NULL);
test_end();
test_begin("connection lost: three attempts");
http_client_set.max_attempts = 3;
test_run_client_server(&http_client_set,
- test_client_connection_lost,
- test_server_connection_lost, 1,
- NULL);
+ test_client_connection_lost,
+ test_server_connection_lost, 1, NULL);
test_end();
test_begin("connection lost: manual retry");
http_client_set.max_attempts = 3;
http_client_set.no_auto_retry = TRUE;
test_run_client_server(&http_client_set,
- test_client_connection_lost,
- test_server_connection_lost, 1,
- NULL);
+ test_client_connection_lost,
+ test_server_connection_lost, 1, NULL);
test_end();
}
/* server */
-static void
-test_connection_lost_100_input(struct server_connection *conn)
+static void test_connection_lost_100_input(struct server_connection *conn)
{
static const char *resp =
"HTTP/1.1 100 Continue\r\n"
"\r\n";
+
o_stream_nsend_str(conn->conn.output, resp);
server_connection_deinit(&conn);
}
};
static void
-test_client_connection_lost_100_response(
- const struct http_response *resp,
- struct _connection_lost_100_ctx *ctx)
+test_client_connection_lost_100_response(const struct http_response *resp,
+ struct _connection_lost_100_ctx *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
const struct http_client_settings *client_set)
{
static const char payload[] =
- "This is a useless payload that only serves as a means to give the "
- "server the opportunity to close the connection before the payload "
- "is finished.";
+ "This is a useless payload that only serves as a means to give "
+ "the server the opportunity to close the connection before the "
+ "payload is finished.";
struct _connection_lost_100_ctx *ctx;
struct http_client_request *hreq;
struct istream *input;
input = i_stream_create_from_data(payload, sizeof(payload)-1);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-lost.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-lost.txt",
test_client_connection_lost_100_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_payload(hreq, input, TRUE);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-lost2.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-lost2.txt",
test_client_connection_lost_100_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_payload(hreq, input, TRUE);
test_begin("connection lost after 100-continue");
http_client_set.max_attempts = 1;
test_run_client_server(&http_client_set,
- test_client_connection_lost_100,
- test_server_connection_lost_100, 1,
- NULL);
+ test_client_connection_lost_100,
+ test_server_connection_lost_100, 1, NULL);
test_end();
}
"HTTP/1.1 200 OK\r\n"
"Content-Length: 0\r\n"
"\r\n";
+
o_stream_nsend_str(conn->conn.output, resp);
server_connection_deinit(&conn);
}
static void
test_client_connection_lost_sub_ioloop_response2(
- const struct http_response *resp,
- struct ioloop *sub_ioloop)
+ const struct http_response *resp, struct ioloop *sub_ioloop)
{
if (debug)
i_debug("SUB-RESPONSE: %u %s", resp->status, resp->reason);
sub_ioloop = io_loop_create();
http_client_switch_ioloop(http_client);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-lost-sub-ioloop3.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-lost-sub-ioloop3.txt",
test_client_connection_lost_sub_ioloop_response2, sub_ioloop);
http_client_request_set_port(hreq, bind_ports[1]);
http_client_request_submit(hreq);
const struct http_client_settings *client_set)
{
static const char payload[] =
- "This is a useless payload that only serves as a means to give the "
- "server the opportunity to close the connection before the payload "
- "is finished.";
+ "This is a useless payload that only serves as a means to give "
+ "the server the opportunity to close the connection before the "
+ "payload is finished.";
struct _connection_lost_sub_ioloop_ctx *ctx;
struct http_client_request *hreq;
struct istream *input;
input = i_stream_create_from_data(payload, sizeof(payload)-1);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-lost-sub-ioloop.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-lost-sub-ioloop.txt",
test_client_connection_lost_sub_ioloop_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_payload(hreq, input, TRUE);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/connection-lost-sub-ioloop2.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/connection-lost-sub-ioloop2.txt",
test_client_connection_lost_sub_ioloop_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_payload(hreq, input, TRUE);
test_begin("connection lost while running sub-ioloop");
http_client_set.max_attempts = 1;
test_run_client_server(&http_client_set,
- test_client_connection_lost_sub_ioloop,
- test_server_connection_lost_sub_ioloop, 2,
- NULL);
+ test_client_connection_lost_sub_ioloop,
+ test_server_connection_lost_sub_ioloop, 2, NULL);
test_end();
}
/* server */
-static void
-test_early_success_input(struct server_connection *conn)
+static void test_early_success_input(struct server_connection *conn)
{
static const char *resp =
"HTTP/1.1 200 OK\r\n"
};
static void
-test_client_early_success_response(
- const struct http_response *resp,
- struct _early_success_ctx *ctx)
+test_client_early_success_response(const struct http_response *resp,
+ struct _early_success_ctx *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
- if (ctx->count == 2)
- test_assert(resp->status == HTTP_CLIENT_REQUEST_ERROR_BAD_RESPONSE);
- else
+ if (ctx->count == 2) {
+ test_assert(resp->status ==
+ HTTP_CLIENT_REQUEST_ERROR_BAD_RESPONSE);
+ } else {
test_assert(resp->status == 200);
+ }
test_assert(resp->reason != NULL && *resp->reason != '\0');
if (--ctx->count == 0) {
io_loop_stop(ioloop);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/early-success.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/early-success.txt",
test_client_early_success_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
chain_input = i_stream_create_chain(&chain);
- input = i_stream_create_copy_from_data
- (str_data(payload), str_len(payload));
+ input = i_stream_create_copy_from_data(str_data(payload),
+ str_len(payload));
i_stream_chain_append(chain, input);
i_stream_unref(&input);
} T_END;
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/early-success2.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/early-success2.txt",
test_client_early_success_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("early succes");
test_run_client_server(&http_client_set,
- test_client_early_success,
- test_server_early_success, 1,
- NULL);
+ test_client_early_success,
+ test_server_early_success, 1, NULL);
test_end();
}
/* server */
-static void
-test_bad_response_input(struct server_connection *conn)
+static void test_bad_response_input(struct server_connection *conn)
{
static const char *resp =
"HTTP/1.1 666 Really bad response\r\n"
"\r\n";
+
o_stream_nsend_str(conn->conn.output, resp);
server_connection_deinit(&conn);
}
};
static void
-test_client_bad_response_response(
- const struct http_response *resp,
- struct _bad_response_ctx *ctx)
+test_client_bad_response_response(const struct http_response *resp,
+ struct _bad_response_ctx *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/bad-response.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/bad-response.txt",
test_client_bad_response_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/bad-response2.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/bad-response2.txt",
test_client_bad_response_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("bad response");
test_run_client_server(&http_client_set,
- test_client_bad_response,
- test_server_bad_response, 1,
- NULL);
+ test_client_bad_response,
+ test_server_bad_response, 1, NULL);
test_end();
}
};
static void
-test_client_request_timed_out1_response(
- const struct http_response *resp,
- struct _request_timed_out1_ctx *ctx)
+test_client_request_timed_out1_response(const struct http_response *resp,
+ struct _request_timed_out1_ctx *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/request-timed-out1-1.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/request-timed-out1-1.txt",
test_client_request_timed_out1_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/request-timed-out1-2.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/request-timed-out1-2.txt",
test_client_request_timed_out1_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
};
static void
-test_client_request_timed_out2_timeout(
- struct _request_timed_out2_ctx *ctx)
+test_client_request_timed_out2_timeout(struct _request_timed_out2_ctx *ctx)
{
timeout_remove(&ctx->to);
i_debug("TIMEOUT");
}
static void
-test_client_request_timed_out2_response(
- const struct http_response *resp,
- struct _request_timed_out2_ctx *ctx)
+test_client_request_timed_out2_response(const struct http_response *resp,
+ struct _request_timed_out2_ctx *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/request-timed-out2-1.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/request-timed-out2-1.txt",
test_client_request_timed_out2_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_attempt_timeout_msecs(hreq, 1000);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/request-timed-out2-2.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/request-timed-out2-2.txt",
test_client_request_timed_out2_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_set_attempt_timeout_msecs(hreq, 1000);
http_client_set.request_timeout_msecs = 1000;
http_client_set.max_attempts = 1;
test_run_client_server(&http_client_set,
- test_client_request_timed_out1,
- test_server_request_timed_out, 1,
- NULL);
+ test_client_request_timed_out1,
+ test_server_request_timed_out, 1, NULL);
test_end();
test_begin("request timed out: two attempts");
http_client_set.request_timeout_msecs = 1000;
http_client_set.max_attempts = 1;
test_run_client_server(&http_client_set,
- test_client_request_timed_out1,
- test_server_request_timed_out, 1,
- NULL);
+ test_client_request_timed_out1,
+ test_server_request_timed_out, 1, NULL);
test_end();
test_begin("request absolutely timed out");
http_client_set.request_absolute_timeout_msecs = 2000;
http_client_set.max_attempts = 3;
test_run_client_server(&http_client_set,
- test_client_request_timed_out1,
- test_server_request_timed_out, 1,
- NULL);
+ test_client_request_timed_out1,
+ test_server_request_timed_out, 1, NULL);
test_end();
test_begin("request double timed out");
http_client_set.request_absolute_timeout_msecs = 2000;
http_client_set.max_attempts = 3;
test_run_client_server(&http_client_set,
- test_client_request_timed_out1,
- test_server_request_timed_out, 1,
- NULL);
+ test_client_request_timed_out1,
+ test_server_request_timed_out, 1, NULL);
test_end();
test_begin("request timed out: specific timeout");
http_client_set.max_attempts = 1;
http_client_set.max_parallel_connections = 1;
test_run_client_server(&http_client_set,
- test_client_request_timed_out2,
- test_server_request_timed_out, 1,
- NULL);
+ test_client_request_timed_out2,
+ test_server_request_timed_out, 1, NULL);
test_end();
test_begin("request timed out: specific timeout (parallel)");
http_client_set.max_attempts = 1;
http_client_set.max_parallel_connections = 4;
test_run_client_server(&http_client_set,
- test_client_request_timed_out2,
- test_server_request_timed_out, 1,
- NULL);
+ test_client_request_timed_out2,
+ test_server_request_timed_out, 1, NULL);
test_end();
}
/* wait a little for server to actually respond to an
already aborted request */
- ctx->to = timeout_add_short(1000,
- test_client_request_aborted_early_timeout, ctx);
+ ctx->to = timeout_add_short(
+ 1000, test_client_request_aborted_early_timeout, ctx);
} else {
/* all done */
i_free(ctx);
}
static bool
-test_client_request_aborted_early(
- const struct http_client_settings *client_set)
+test_client_request_aborted_early(const struct http_client_settings *client_set)
{
struct http_client_request *hreq;
struct _request_aborted_early_ctx *ctx;
http_client = http_client_init(client_set);
- hreq = ctx->req1 = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/request-aborted-early.txt",
+ hreq = ctx->req1 = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/request-aborted-early.txt",
test_client_request_aborted_early_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = ctx->req2 = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/request-aborted-early2.txt",
+ hreq = ctx->req2 = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/request-aborted-early2.txt",
test_client_request_aborted_early_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- ctx->to = timeout_add_short(500,
- test_client_request_aborted_early_timeout, ctx);
+ ctx->to = timeout_add_short(
+ 500, test_client_request_aborted_early_timeout, ctx);
return TRUE;
}
test_begin("request aborted early");
test_run_client_server(&http_client_set,
- test_client_request_aborted_early,
- test_server_request_aborted_early, 1,
- NULL);
+ test_client_request_aborted_early,
+ test_server_request_aborted_early, 1, NULL);
test_end();
}
http_client = http_client_init(client_set);
- hreq = ctx->req = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/request-failed-blocking.txt",
+ hreq = ctx->req = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/request-failed-blocking.txt",
test_client_request_failed_blocking_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
test_begin("request failed blocking");
test_run_client_server(&http_client_set,
- test_client_request_failed_blocking,
- test_server_request_failed_blocking, 1,
- NULL);
+ test_client_request_failed_blocking,
+ test_server_request_failed_blocking, 1, NULL);
test_end();
}
}
static void
-test_client_client_deinit_early_timeout(
- struct _client_deinit_early_ctx *ctx)
+test_client_client_deinit_early_timeout(struct _client_deinit_early_ctx *ctx)
{
timeout_remove(&ctx->to);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/client-deinit-early.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/client-deinit-early.txt",
test_client_client_deinit_early_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/client-deinit-early2.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/client-deinit-early2.txt",
test_client_client_deinit_early_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- ctx->to = timeout_add_short(500,
- test_client_client_deinit_early_timeout, ctx);
+ ctx->to = timeout_add_short(
+ 500, test_client_client_deinit_early_timeout, ctx);
return TRUE;
}
test_begin("client deinit early");
test_run_client_server(&http_client_set,
- test_client_client_deinit_early,
- test_server_client_deinit_early, 1,
- NULL);
+ test_client_client_deinit_early,
+ test_server_client_deinit_early, 1, NULL);
test_end();
}
/* server */
-static void
-test_retry_with_delay_input(struct server_connection *conn)
+static void test_retry_with_delay_input(struct server_connection *conn)
{
string_t *resp;
resp = t_str_new(512);
- str_printfa(resp,
- "HTTP/1.1 500 Internal Server Error\r\n"
- "\r\n");
- o_stream_nsend(conn->conn.output,
- str_data(resp), str_len(resp));
+ str_printfa(resp,
+ "HTTP/1.1 500 Internal Server Error\r\n"
+ "\r\n");
+ o_stream_nsend(conn->conn.output, str_data(resp), str_len(resp));
server_connection_deinit(&conn);
}
http_client = http_client_init(client_set);
- ctx->req = hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/retry-with-delay.txt",
+ ctx->req = hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/retry-with-delay.txt",
test_client_retry_with_delay_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("retry with delay");
test_run_client_server(&http_client_set,
- test_client_retry_with_delay,
- test_server_retry_with_delay, 1,
- NULL);
+ test_client_retry_with_delay,
+ test_server_retry_with_delay, 1, NULL);
test_end();
}
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
- test_assert(resp->status == HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
+ test_assert(resp->status ==
+ HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
test_assert(resp->reason != NULL && *resp->reason != '\0');
if (--ctx->count == 0) {
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "example.com", "/dns-service-failure.txt",
+ hreq = http_client_request(
+ http_client, "GET", "example.com", "/dns-service-failure.txt",
test_client_dns_service_failure_response, ctx);
http_client_request_set_port(hreq, 80);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", "example.com", "/dns-service-failure2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "example.com", "/dns-service-failure2.txt",
test_client_dns_service_failure_response, ctx);
http_client_request_set_port(hreq, 80);
http_client_request_submit(hreq);
test_begin("dns service failure");
test_run_client_server(&http_client_set,
- test_client_dns_service_failure,
- NULL, 0, NULL);
+ test_client_dns_service_failure,
+ NULL, 0, NULL);
test_end();
}
/* dns */
-static void
-test_dns_timeout_input(struct server_connection *conn ATTR_UNUSED)
+static void test_dns_timeout_input(struct server_connection *conn ATTR_UNUSED)
{
/* hang */
sleep(100);
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
- test_assert(resp->status == HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
+ test_assert(resp->status ==
+ HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
test_assert(resp->reason != NULL && *resp->reason != '\0');
if (--ctx->count == 0) {
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "example.com", "/dns-timeout.txt",
+ hreq = http_client_request(
+ http_client, "GET", "example.com", "/dns-timeout.txt",
test_client_dns_timeout_response, ctx);
http_client_request_set_port(hreq, 80);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", "example.com", "/dns-timeout2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "example.com", "/dns-timeout2.txt",
test_client_dns_timeout_response, ctx);
http_client_request_set_port(hreq, 80);
http_client_request_submit(hreq);
test_begin("dns timeout");
test_run_client_server(&http_client_set,
- test_client_dns_timeout,
- NULL, 0,
- test_dns_dns_timeout);
+ test_client_dns_timeout, NULL, 0,
+ test_dns_dns_timeout);
test_end();
}
}
o_stream_nsend_str(conn->conn.output,
- t_strdup_printf("%d\tFAIL\n", EAI_FAIL));
+ t_strdup_printf("%d\tFAIL\n", EAI_FAIL));
server_connection_deinit(&conn);
}
};
static void
-test_client_dns_lookup_failure_response(
- const struct http_response *resp,
- struct _dns_lookup_failure *ctx)
+test_client_dns_lookup_failure_response(const struct http_response *resp,
+ struct _dns_lookup_failure *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
- test_assert(resp->status == HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
+ test_assert(resp->status ==
+ HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
test_assert(resp->reason != NULL && *resp->reason != '\0');
if (--ctx->count == 0) {
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "example.com", "/dns-lookup-failure.txt",
+ hreq = http_client_request(
+ http_client, "GET", "example.com", "/dns-lookup-failure.txt",
test_client_dns_lookup_failure_response, ctx);
http_client_request_set_port(hreq, 80);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", "example.com", "/dns-lookup-failure2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "example.com", "/dns-lookup-failure2.txt",
test_client_dns_lookup_failure_response, ctx);
http_client_request_set_port(hreq, 80);
http_client_request_submit(hreq);
test_begin("dns lookup failure");
test_run_client_server(&http_client_set,
- test_client_dns_lookup_failure,
- NULL, 0,
- test_dns_dns_lookup_failure);
+ test_client_dns_lookup_failure, NULL, 0,
+ test_dns_dns_lookup_failure);
test_end();
}
o_stream_nsend_str(conn->conn.output, "VERSION\tdns\t1\t0\n");
}
- while ((line=i_stream_read_next_line(conn->conn.input)) != NULL) {
+ while ((line = i_stream_read_next_line(conn->conn.input)) != NULL) {
if (str_begins(line, "VERSION"))
continue;
if (debug)
if (count == 0) {
o_stream_nsend_str(conn->conn.output,
- "0\t127.0.0.1\n");
+ "0\t127.0.0.1\n");
} else {
- o_stream_nsend_str(conn->conn.output,
+ o_stream_nsend_str(
+ conn->conn.output,
t_strdup_printf("%d\tFAIL\n", EAI_FAIL));
if (count > 4) {
server_connection_deinit(&conn);
resp = t_str_new(512);
str_printfa(resp,
- "HTTP/1.1 200 OK\r\n"
- "Connection: close\r\n"
- "\r\n");
- o_stream_nsend(conn->conn.output,
- str_data(resp), str_len(resp));
+ "HTTP/1.1 200 OK\r\n"
+ "Connection: close\r\n"
+ "\r\n");
+ o_stream_nsend(conn->conn.output, str_data(resp), str_len(resp));
server_connection_deinit(&conn);
}
};
static void
-test_client_dns_lookup_ttl_response_stage2(
- const struct http_response *resp,
- struct _dns_lookup_ttl *ctx)
+test_client_dns_lookup_ttl_response_stage2(const struct http_response *resp,
+ struct _dns_lookup_ttl *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
- test_assert(resp->status == HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
+ test_assert(resp->status ==
+ HTTP_CLIENT_REQUEST_ERROR_HOST_LOOKUP_FAILED);
test_assert(resp->reason != NULL && *resp->reason != '\0');
if (--ctx->count == 0) {
}
}
-static void
-test_client_dns_lookup_ttl_stage2_start(struct _dns_lookup_ttl *ctx)
+static void test_client_dns_lookup_ttl_stage2_start(struct _dns_lookup_ttl *ctx)
{
struct http_client_request *hreq;
ctx->count = 2;
- hreq = http_client_request(ctx->client,
- "GET", "example.com", "/dns-lookup-ttl-stage2.txt",
+ hreq = http_client_request(
+ ctx->client, "GET", "example.com",
+ "/dns-lookup-ttl-stage2.txt",
test_client_dns_lookup_ttl_response_stage2, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(ctx->client,
- "GET", "example.com", "/dns-lookup-ttl2-stage2.txt",
+ hreq = http_client_request(
+ ctx->client, "GET", "example.com",
+ "/dns-lookup-ttl2-stage2.txt",
test_client_dns_lookup_ttl_response_stage2, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
}
static void
-test_client_dns_lookup_ttl_response_stage1(
- const struct http_response *resp,
- struct _dns_lookup_ttl *ctx)
+test_client_dns_lookup_ttl_response_stage1(const struct http_response *resp,
+ struct _dns_lookup_ttl *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
ctx->client = http_client = http_client_init(client_set);
- hreq = http_client_request(ctx->client,
- "GET", "example.com", "/dns-lookup-ttl-stage1.txt",
+ hreq = http_client_request(
+ ctx->client, "GET", "example.com",
+ "/dns-lookup-ttl-stage1.txt",
test_client_dns_lookup_ttl_response_stage1, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(ctx->client,
- "GET", "example.com", "/dns-lookup-ttl2-stage1.txt",
+ hreq = http_client_request(
+ ctx->client, "GET", "example.com",
+ "/dns-lookup-ttl2-stage1.txt",
test_client_dns_lookup_ttl_response_stage1, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("dns lookup ttl");
test_run_client_server(&http_client_set,
- test_client_dns_lookup_ttl,
- test_server_dns_lookup_ttl, 1,
- test_dns_dns_lookup_ttl);
+ test_client_dns_lookup_ttl,
+ test_server_dns_lookup_ttl, 1,
+ test_dns_dns_lookup_ttl);
test_end();
}
/* server */
-static void
-test_peer_reuse_failure_input(struct server_connection *conn)
+static void test_peer_reuse_failure_input(struct server_connection *conn)
{
static unsigned int seq = 0;
static const char *resp =
"HTTP/1.1 200 OK\r\n"
"\r\n";
+
o_stream_nsend_str(conn->conn.output, resp);
if (seq++ > 2) {
server_connection_deinit(&conn);
};
static void
-test_client_peer_reuse_failure_response2(
- const struct http_response *resp,
- struct _peer_reuse_failure *ctx)
+test_client_peer_reuse_failure_response2(const struct http_response *resp,
+ struct _peer_reuse_failure *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
timeout_remove(&ctx->to);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/peer-reuse-next.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip),
+ "/peer-reuse-next.txt",
test_client_peer_reuse_failure_response2, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
}
static void
-test_client_peer_reuse_failure_response1(
- const struct http_response *resp,
- struct _peer_reuse_failure *ctx)
+test_client_peer_reuse_failure_response1(const struct http_response *resp,
+ struct _peer_reuse_failure *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
test_assert(resp->status == 200);
ctx->first = FALSE;
- ctx->to = timeout_add_short(500, test_client_peer_reuse_failure_next, ctx);
+ ctx->to = timeout_add_short(
+ 500, test_client_peer_reuse_failure_next, ctx);
} else {
test_assert(http_response_is_internal_error(resp));
}
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/peer-reuse.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip), "/peer-reuse.txt",
test_client_peer_reuse_failure_response1, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/peer-reuse.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip), "/peer-reuse.txt",
test_client_peer_reuse_failure_response1, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", net_ip2addr(&bind_ip), "/peer-reuse.txt",
+ hreq = http_client_request(
+ http_client, "GET", net_ip2addr(&bind_ip), "/peer-reuse.txt",
test_client_peer_reuse_failure_response1, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("peer reuse failure");
test_run_client_server(&http_client_set,
- test_client_peer_reuse_failure,
- test_server_peer_reuse_failure, 1,
- NULL);
+ test_client_peer_reuse_failure,
+ test_server_peer_reuse_failure, 1, NULL);
test_end();
}
/* dns */
-static void
-test_dns_reconnect_failure_input(struct server_connection *conn)
+static void test_dns_reconnect_failure_input(struct server_connection *conn)
{
static unsigned int count = 0;
const char *line;
o_stream_nsend_str(conn->conn.output, "VERSION\tdns\t1\t0\n");
}
- while ((line=i_stream_read_next_line(conn->conn.input)) != NULL) {
+ while ((line = i_stream_read_next_line(conn->conn.input)) != NULL) {
if (str_begins(line, "VERSION"))
continue;
if (debug)
if (count == 0) {
o_stream_nsend_str(conn->conn.output,
- "0\t127.0.0.1\n");
+ "0\t127.0.0.1\n");
} else {
- o_stream_nsend_str(conn->conn.output,
+ o_stream_nsend_str(
+ conn->conn.output,
t_strdup_printf("%d\tFAIL\n", EAI_FAIL));
if (count > 4) {
server_connection_deinit(&conn);
test_server_input = test_dns_reconnect_failure_input;
test_server_run(0);
}
+
/* server */
-static void
-test_reconnect_failure_input(struct server_connection *conn)
+static void test_reconnect_failure_input(struct server_connection *conn)
{
static const char *resp =
"HTTP/1.1 200 OK\r\n"
};
static void
-test_client_reconnect_failure_response2(
- const struct http_response *resp,
- struct _reconnect_failure_ctx *ctx)
+test_client_reconnect_failure_response2(const struct http_response *resp,
+ struct _reconnect_failure_ctx *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
}
static void
-test_client_reconnect_failure_next(
- struct _reconnect_failure_ctx *ctx)
+test_client_reconnect_failure_next(struct _reconnect_failure_ctx *ctx)
{
struct http_client_request *hreq;
timeout_remove(&ctx->to);
- hreq = http_client_request(http_client,
- "GET", "example.com", "/reconnect-failure-2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "example.com", "/reconnect-failure-2.txt",
test_client_reconnect_failure_response2, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
}
static void
-test_client_reconnect_failure_response1(
- const struct http_response *resp,
- struct _reconnect_failure_ctx *ctx)
+test_client_reconnect_failure_response1(const struct http_response *resp,
+ struct _reconnect_failure_ctx *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
test_assert(resp->status == 200);
test_assert(resp->reason != NULL && *resp->reason != '\0');
- ctx->to = timeout_add_short(5000,
- test_client_reconnect_failure_next, ctx);
+ ctx->to = timeout_add_short(
+ 5000, test_client_reconnect_failure_next, ctx);
}
static bool
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "example.com", "/reconnect-failure-1.txt",
+ hreq = http_client_request(
+ http_client, "GET", "example.com", "/reconnect-failure-1.txt",
test_client_reconnect_failure_response1, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("reconnect failure");
test_run_client_server(&http_client_set,
- test_client_reconnect_failure,
- test_server_reconnect_failure, 1,
- test_dns_reconnect_failure);
+ test_client_reconnect_failure,
+ test_server_reconnect_failure, 1,
+ test_dns_reconnect_failure);
test_end();
}
/* dns */
-static void
-test_multi_ip_attempts_input(struct server_connection *conn)
+static void test_multi_ip_attempts_input(struct server_connection *conn)
{
unsigned int count = 0;
const char *line;
o_stream_nsend_str(conn->conn.output, "VERSION\tdns\t1\t0\n");
}
- while ((line=i_stream_read_next_line(conn->conn.input)) != NULL) {
+ while ((line = i_stream_read_next_line(conn->conn.input)) != NULL) {
if (str_begins(line, "VERSION"))
continue;
if (debug)
if (strcmp(line, "IP\ttest1.local") == 0) {
o_stream_nsend_str(conn->conn.output,
- "0\t127.0.0.4\t127.0.0.3\t"
- "127.0.0.2\t127.0.0.1\n");
+ "0\t127.0.0.4\t127.0.0.3\t"
+ "127.0.0.2\t127.0.0.1\n");
continue;
}
/* server */
-static void
-test_server_multi_ip_attempts_input(struct server_connection *conn)
+static void test_server_multi_ip_attempts_input(struct server_connection *conn)
{
string_t *resp;
resp = t_str_new(512);
str_printfa(resp,
- "HTTP/1.1 200 OK\r\n"
- "Connection: close\r\n"
- "\r\n");
- o_stream_nsend(conn->conn.output,
- str_data(resp), str_len(resp));
+ "HTTP/1.1 200 OK\r\n"
+ "Connection: close\r\n"
+ "\r\n");
+ o_stream_nsend(conn->conn.output, str_data(resp), str_len(resp));
server_connection_deinit(&conn);
}
};
static void
-test_client_multi_ip_attempts_response(
- const struct http_response *resp,
- struct _multi_ip_attempts *ctx)
+test_client_multi_ip_attempts_response(const struct http_response *resp,
+ struct _multi_ip_attempts *ctx)
{
if (debug)
i_debug("RESPONSE: %u %s", resp->status, resp->reason);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "test1.local", "/multi-ip-attempts.txt",
+ hreq = http_client_request(
+ http_client, "GET", "test1.local", "/multi-ip-attempts.txt",
test_client_multi_ip_attempts_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", "test1.local", "/multi-ip-attempts2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "test1.local", "/multi-ip-attempts2.txt",
test_client_multi_ip_attempts_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
http_client = http_client_init(client_set);
- hreq = http_client_request(http_client,
- "GET", "test2.local", "/multi-ip-attempts.txt",
+ hreq = http_client_request(
+ http_client, "GET", "test2.local", "/multi-ip-attempts.txt",
test_client_multi_ip_attempts_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
- hreq = http_client_request(http_client,
- "GET", "test2.local", "/multi-ip-attempts2.txt",
+ hreq = http_client_request(
+ http_client, "GET", "test2.local", "/multi-ip-attempts2.txt",
test_client_multi_ip_attempts_response, ctx);
http_client_request_set_port(hreq, bind_ports[0]);
http_client_request_submit(hreq);
test_begin("multi IP attempts (connection refused)");
test_run_client_server(&http_client_set,
- test_client_multi_ip_attempts1,
- test_server_multi_ip_attempts, 1,
- test_dns_multi_ip_attempts);
+ test_client_multi_ip_attempts1,
+ test_server_multi_ip_attempts, 1,
+ test_dns_multi_ip_attempts);
test_end();
test_begin("multi IP attempts (connect timeout)");
test_run_client_server(&http_client_set,
- test_client_multi_ip_attempts2,
- test_server_multi_ip_attempts, 1,
- test_dns_multi_ip_attempts);
+ test_client_multi_ip_attempts2,
+ test_server_multi_ip_attempts, 1,
+ test_dns_multi_ip_attempts);
test_end();
http_client_set.soft_connect_timeout_msecs = 100;
test_begin("multi IP attempts (soft connect timeout)");
test_run_client_server(&http_client_set,
- test_client_multi_ip_attempts2,
- test_server_multi_ip_attempts, 1,
- test_dns_multi_ip_attempts);
+ test_client_multi_ip_attempts2,
+ test_server_multi_ip_attempts, 1,
+ test_dns_multi_ip_attempts);
test_end();
}
* Test client
*/
-static void
-test_client_defaults(struct http_client_settings *http_set)
+static void test_client_defaults(struct http_client_settings *http_set)
{
/* client settings */
i_zero(http_set);
http_set->debug = debug;
}
-static void
-test_client_progress_timeout(void *context ATTR_UNUSED)
+static void test_client_progress_timeout(void *context ATTR_UNUSED)
{
/* Terminate test due to lack of progress */
test_assert(FALSE);
return FALSE;
to_client_progress = timeout_add(CLIENT_PROGRESS_TIMEOUT*1000,
- test_client_progress_timeout, NULL);
-
+ test_client_progress_timeout, NULL);
return TRUE;
}
/* client connection */
-static void
-server_connection_input(struct connection *_conn)
+static void server_connection_input(struct connection *_conn)
{
struct server_connection *conn = (struct server_connection *)_conn;
test_server_input(conn);
}
-static void
-server_connection_init(int fd)
+static void server_connection_init(int fd)
{
struct server_connection *conn;
pool_t pool;
conn = p_new(pool, struct server_connection, 1);
conn->pool = pool;
- connection_init_server
- (server_conn_list, &conn->conn, "server connection", fd, fd);
+ connection_init_server(server_conn_list, &conn->conn,
+ "server connection", fd, fd);
}
-static void
-server_connection_deinit(struct server_connection **_conn)
+static void server_connection_deinit(struct server_connection **_conn)
{
struct server_connection *conn = *_conn;
pool_unref(&conn->pool);
}
-static void
-server_connection_destroy(struct connection *_conn)
+static void server_connection_destroy(struct connection *_conn)
{
- struct server_connection *conn =
- (struct server_connection *)_conn;
+ struct server_connection *conn = (struct server_connection *)_conn;
server_connection_deinit(&conn);
}
-static void
-server_connection_accept(void *context ATTR_UNUSED)
+static void server_connection_accept(void *context ATTR_UNUSED)
{
int fd;
server_index = index;
/* open server socket */
- io_listen = io_add(fd_listen,
- IO_READ, server_connection_accept, NULL);
+ io_listen = io_add(fd_listen, IO_READ, server_connection_accept, NULL);
- server_conn_list = connection_list_init
- (&server_connection_set, &server_connection_vfuncs);
+ server_conn_list = connection_list_init(&server_connection_set,
+ &server_connection_vfuncs);
io_loop_run(ioloop);
}
}
-static void test_run_client_server(
- const struct http_client_settings *client_set,
- test_client_init_t client_test,
- test_server_init_t server_test,
- unsigned int server_tests_count,
- test_dns_init_t dns_test)
+static void
+test_run_client_server(const struct http_client_settings *client_set,
+ test_client_init_t client_test,
+ test_server_init_t server_test,
+ unsigned int server_tests_count,
+ test_dns_init_t dns_test)
{
unsigned int i;
server_pids[i] = (pid_t)-1;
server_pids_count = 0;
hostpid_init();
- if (debug)
- i_debug("server[%d]: PID=%s", i+1, my_pid);
+ if (debug) {
+ i_debug("server[%d]: PID=%s",
+ i+1, my_pid);
+ }
/* child: server */
ioloop = io_loop_create();
server_test(i);
i_close_fd(&fd_listen);
i_free(bind_ports);
i_free(server_pids);
- /* wait for it to be killed; this way, valgrind will not
- object to this process going away inelegantly. */
+ /* wait for it to be killed; this way, valgrind
+ will not object to this process going away
+ inelegantly. */
sleep(60);
exit(1);
}
volatile sig_atomic_t terminating = 0;
-static void
-test_signal_handler(int signo)
+static void test_signal_handler(int signo)
{
if (terminating != 0)
raise(signo);
(void)signal(SIGSEGV, test_signal_handler);
(void)signal(SIGABRT, test_signal_handler);
- while ((c = getopt(argc, argv, "D")) > 0) {
+ while ((c = getopt(argc, argv, "D")) > 0) {
switch (c) {
case 'D':
debug = TRUE;
default:
i_fatal("Usage: %s [-D]", argv[0]);
}
- }
+ }
/* listen on localhost */
i_zero(&bind_ip);