mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-09 12:28:19 -04:00
test/https: cover multiple request over the same connection
Introduce two new tests: - http/https_connection # fail - http/https_persist_connection # ok Reported-by: liutao74748@163.com
This commit is contained in:
parent
e6ae069b48
commit
45247e6fd9
@ -1004,12 +1004,21 @@ static void http_request_empty_done(struct evhttp_request *, void *);
|
||||
|
||||
static void
|
||||
http_connection_test_(struct basic_test_data *data, int persistent,
|
||||
const char *address, struct evdns_base *dnsbase, int ipv6, int family)
|
||||
const char *address, struct evdns_base *dnsbase, int ipv6, int family,
|
||||
int ssl)
|
||||
{
|
||||
ev_uint16_t port = 0;
|
||||
struct evhttp_connection *evcon = NULL;
|
||||
struct evhttp_request *req = NULL;
|
||||
struct evhttp *http = http_setup(&port, data->base, ipv6);
|
||||
struct evhttp *http;
|
||||
|
||||
int mask = 0;
|
||||
if (ipv6)
|
||||
mask |= HTTP_BIND_IPV6;
|
||||
if (ssl)
|
||||
mask |= HTTP_BIND_SSL;
|
||||
|
||||
http = http_setup(&port, data->base, mask);
|
||||
|
||||
test_ok = 0;
|
||||
if (!http && ipv6) {
|
||||
@ -1017,7 +1026,21 @@ http_connection_test_(struct basic_test_data *data, int persistent,
|
||||
}
|
||||
tt_assert(http);
|
||||
|
||||
evcon = evhttp_connection_base_new(data->base, dnsbase, address, port);
|
||||
if (ssl) {
|
||||
#ifdef EVENT__HAVE_OPENSSL
|
||||
SSL *ssl = SSL_new(get_ssl_ctx());
|
||||
struct bufferevent *bev = bufferevent_openssl_socket_new(
|
||||
data->base, -1, ssl,
|
||||
BUFFEREVENT_SSL_CONNECTING, BEV_OPT_DEFER_CALLBACKS);
|
||||
bufferevent_openssl_set_allow_dirty_shutdown(bev, 1);
|
||||
|
||||
evcon = evhttp_connection_base_bufferevent_new(data->base, dnsbase, bev, address, port);
|
||||
#else
|
||||
tt_skip();
|
||||
#endif
|
||||
} else {
|
||||
evcon = evhttp_connection_base_new(data->base, dnsbase, address, port);
|
||||
}
|
||||
tt_assert(evcon);
|
||||
evhttp_connection_set_family(evcon, family);
|
||||
|
||||
@ -1093,12 +1116,12 @@ http_connection_test_(struct basic_test_data *data, int persistent,
|
||||
static void
|
||||
http_connection_test(void *arg)
|
||||
{
|
||||
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_UNSPEC);
|
||||
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_UNSPEC, 0);
|
||||
}
|
||||
static void
|
||||
http_persist_connection_test(void *arg)
|
||||
{
|
||||
http_connection_test_(arg, 1, "127.0.0.1", NULL, 0, AF_UNSPEC);
|
||||
http_connection_test_(arg, 1, "127.0.0.1", NULL, 0, AF_UNSPEC, 0);
|
||||
}
|
||||
|
||||
static struct regress_dns_server_table search_table[] = {
|
||||
@ -1540,6 +1563,11 @@ http_request_done(struct evhttp_request *req, void *arg)
|
||||
{
|
||||
const char *what = arg;
|
||||
|
||||
if (!req) {
|
||||
fprintf(stderr, "FAILED\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (evhttp_request_get_response_code(req) != HTTP_OK) {
|
||||
fprintf(stderr, "FAILED\n");
|
||||
exit(1);
|
||||
@ -4294,7 +4322,7 @@ http_ipv6_for_domain_test_impl(void *arg, int family)
|
||||
evdns_base_nameserver_ip_add(dns_base, address);
|
||||
|
||||
http_connection_test_(arg, 0 /* not persistent */, "localhost", dns_base,
|
||||
1 /* ipv6 */, family);
|
||||
1 /* ipv6 */, family, 0);
|
||||
|
||||
end:
|
||||
if (dns_base)
|
||||
@ -4372,12 +4400,12 @@ http_get_addr_test(void *arg)
|
||||
static void
|
||||
http_set_family_test(void *arg)
|
||||
{
|
||||
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_UNSPEC);
|
||||
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_UNSPEC, 0);
|
||||
}
|
||||
static void
|
||||
http_set_family_ipv4_test(void *arg)
|
||||
{
|
||||
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_INET);
|
||||
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_INET, 0);
|
||||
}
|
||||
static void
|
||||
http_set_family_ipv6_test(void *arg)
|
||||
@ -4505,6 +4533,10 @@ static void https_connection_fail_test(void *arg)
|
||||
{ return http_connection_fail_test_impl(arg, 1); }
|
||||
static void https_write_during_read_test(void *arg)
|
||||
{ return http_write_during_read_test_impl(arg, 1); }
|
||||
static void https_connection_test(void *arg)
|
||||
{ return http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_UNSPEC, 1); }
|
||||
static void https_persist_connection_test(void *arg)
|
||||
{ return http_connection_test_(arg, 1, "127.0.0.1", NULL, 0, AF_UNSPEC, 1); }
|
||||
#endif
|
||||
|
||||
struct testcase_t http_testcases[] = {
|
||||
@ -4595,6 +4627,8 @@ struct testcase_t http_testcases[] = {
|
||||
HTTPS(stream_out),
|
||||
HTTPS(connection_fail),
|
||||
HTTPS(write_during_read),
|
||||
HTTPS(connection),
|
||||
HTTPS(persist_connection),
|
||||
#endif
|
||||
|
||||
END_OF_TESTCASES
|
||||
|
Loading…
x
Reference in New Issue
Block a user