2006-01-22 05:08:50 +00:00
|
|
|
/*
|
2009-01-27 22:34:36 +00:00
|
|
|
* Copyright (c) 2003-2007 Niels Provos <provos@citi.umich.edu>
|
2012-02-10 17:29:53 -05:00
|
|
|
* Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
|
2006-01-22 05:08:50 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2012-01-24 16:08:00 -05:00
|
|
|
#include "util-internal.h"
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2011-05-25 19:50:56 -04:00
|
|
|
#ifdef _WIN32
|
2006-01-22 05:08:50 +00:00
|
|
|
#include <winsock2.h>
|
2011-04-23 01:47:43 -04:00
|
|
|
#include <ws2tcpip.h>
|
2006-01-22 05:08:50 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2010-07-07 16:45:03 -04:00
|
|
|
#include "event2/event-config.h"
|
2006-01-22 05:08:50 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2012-02-29 15:07:31 -05:00
|
|
|
#ifdef EVENT__HAVE_SYS_TIME_H
|
2006-01-22 05:08:50 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/queue.h>
|
2011-05-25 19:50:56 -04:00
|
|
|
#ifndef _WIN32
|
2006-01-22 05:08:50 +00:00
|
|
|
#include <sys/socket.h>
|
2009-01-22 02:47:35 +00:00
|
|
|
#include <signal.h>
|
2006-01-22 05:08:50 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <netdb.h>
|
2007-09-20 19:08:20 +00:00
|
|
|
#endif
|
2006-01-22 05:08:50 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2010-01-14 17:05:00 -08:00
|
|
|
#include "event2/dns.h"
|
|
|
|
|
2010-10-21 12:27:16 -04:00
|
|
|
#include "event2/event.h"
|
|
|
|
#include "event2/http.h"
|
|
|
|
#include "event2/buffer.h"
|
|
|
|
#include "event2/bufferevent.h"
|
2015-11-05 10:58:41 +03:00
|
|
|
#include "event2/bufferevent_ssl.h"
|
2011-01-31 16:37:27 -05:00
|
|
|
#include "event2/util.h"
|
2015-11-05 10:58:41 +03:00
|
|
|
#include "event2/listener.h"
|
2009-01-13 20:26:37 +00:00
|
|
|
#include "log-internal.h"
|
2006-06-10 22:28:21 +00:00
|
|
|
#include "http-internal.h"
|
2009-01-30 17:44:13 +00:00
|
|
|
#include "regress.h"
|
2010-01-14 17:05:00 -08:00
|
|
|
#include "regress_testutils.h"
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2020-05-19 01:05:50 +03:00
|
|
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
|
|
|
|
|
2021-09-19 10:54:27 +03:00
|
|
|
#if EV_WINDOWS
|
|
|
|
#define SKIP_UNDER_WINDOWS TT_SKIP
|
|
|
|
#else
|
|
|
|
#define SKIP_UNDER_WINDOWS 0
|
|
|
|
#endif
|
|
|
|
|
2007-08-19 02:41:23 +00:00
|
|
|
/* set if a test needs to call loopexit on a base */
|
2010-11-03 14:13:20 -04:00
|
|
|
static struct event_base *exit_base;
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2008-07-02 06:08:16 +00:00
|
|
|
static char const BASIC_REQUEST_BODY[] = "This is funny";
|
|
|
|
|
2016-01-08 13:36:20 -08:00
|
|
|
/* defines an extended HTTP method "CUSTOM"
|
|
|
|
* without body */
|
|
|
|
#define EVHTTP_REQ_CUSTOM ((EVHTTP_REQ_MAX) << 1)
|
|
|
|
|
|
|
|
static int ext_method_cb(struct evhttp_ext_method *p)
|
|
|
|
{
|
|
|
|
if (p == NULL)
|
|
|
|
return -1;
|
|
|
|
if (p->method) {
|
|
|
|
if (strcmp(p->method, "CUSTOM") == 0) {
|
|
|
|
p->type = EVHTTP_REQ_CUSTOM;
|
|
|
|
p->flags = 0; /*EVHTTP_METHOD_HAS_BODY*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p->type == EVHTTP_REQ_CUSTOM) {
|
|
|
|
p->method = "CUSTOM";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-05-12 03:12:09 +00:00
|
|
|
static void http_basic_cb(struct evhttp_request *req, void *arg);
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
static void http_timeout_cb(struct evhttp_request *req, void *arg);
|
2015-09-09 17:45:44 +03:00
|
|
|
static void http_large_cb(struct evhttp_request *req, void *arg);
|
2008-05-12 03:12:09 +00:00
|
|
|
static void http_chunked_cb(struct evhttp_request *req, void *arg);
|
2021-01-18 23:23:42 +03:00
|
|
|
static void http_chunked_input_cb(struct evhttp_request *req, void *arg);
|
2008-05-12 03:12:09 +00:00
|
|
|
static void http_post_cb(struct evhttp_request *req, void *arg);
|
|
|
|
static void http_put_cb(struct evhttp_request *req, void *arg);
|
2019-03-13 10:51:55 +03:00
|
|
|
static void http_genmethod_cb(struct evhttp_request *req, void *arg);
|
2016-01-08 13:36:20 -08:00
|
|
|
static void http_custom_cb(struct evhttp_request *req, void *arg);
|
2008-05-12 03:12:09 +00:00
|
|
|
static void http_delay_cb(struct evhttp_request *req, void *arg);
|
2008-12-19 22:42:51 +00:00
|
|
|
static void http_large_delay_cb(struct evhttp_request *req, void *arg);
|
2010-01-11 19:04:11 -05:00
|
|
|
static void http_badreq_cb(struct evhttp_request *req, void *arg);
|
2008-05-12 03:12:09 +00:00
|
|
|
static void http_dispatcher_cb(struct evhttp_request *req, void *arg);
|
2014-01-05 20:35:46 -05:00
|
|
|
static void http_on_complete_cb(struct evhttp_request *req, void *arg);
|
2013-03-22 14:35:47 +04:00
|
|
|
|
2015-11-05 10:58:41 +03:00
|
|
|
#define HTTP_BIND_IPV6 1
|
2020-09-06 15:33:32 +08:00
|
|
|
#define HTTP_OPENSSL 2
|
2016-12-07 03:07:59 +03:00
|
|
|
#define HTTP_SSL_FILTER 4
|
2020-09-06 15:33:32 +08:00
|
|
|
#define HTTP_MBEDTLS 8
|
2010-09-03 18:48:31 -04:00
|
|
|
static int
|
2015-11-05 10:58:41 +03:00
|
|
|
http_bind(struct evhttp *myhttp, ev_uint16_t *pport, int mask)
|
2010-09-03 18:48:31 -04:00
|
|
|
{
|
|
|
|
int port;
|
|
|
|
struct evhttp_bound_socket *sock;
|
2015-11-05 10:58:41 +03:00
|
|
|
int ipv6 = mask & HTTP_BIND_IPV6;
|
2010-09-03 18:48:31 -04:00
|
|
|
|
2013-01-27 02:17:02 +04:00
|
|
|
if (ipv6)
|
|
|
|
sock = evhttp_bind_socket_with_handle(myhttp, "::1", *pport);
|
|
|
|
else
|
|
|
|
sock = evhttp_bind_socket_with_handle(myhttp, "127.0.0.1", *pport);
|
|
|
|
|
2014-03-18 18:36:32 -04:00
|
|
|
if (sock == NULL) {
|
|
|
|
if (ipv6)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
event_errx(1, "Could not start web server");
|
|
|
|
}
|
2010-09-03 18:48:31 -04:00
|
|
|
|
|
|
|
port = regress_get_socket_port(evhttp_bound_socket_get_fd(sock));
|
|
|
|
if (port < 0)
|
|
|
|
return -1;
|
|
|
|
*pport = (ev_uint16_t) port;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-06 10:13:13 +03:00
|
|
|
#ifdef EVENT__HAVE_OPENSSL
|
2015-11-05 10:58:41 +03:00
|
|
|
static struct bufferevent *
|
|
|
|
https_bev(struct event_base *base, void *arg)
|
|
|
|
{
|
|
|
|
SSL *ssl = SSL_new(get_ssl_ctx());
|
|
|
|
|
2018-10-27 19:34:52 +03:00
|
|
|
SSL_use_certificate(ssl, ssl_getcert(ssl_getkey()));
|
2015-11-05 10:58:41 +03:00
|
|
|
SSL_use_PrivateKey(ssl, ssl_getkey());
|
|
|
|
|
|
|
|
return bufferevent_openssl_socket_new(
|
|
|
|
base, -1, ssl, BUFFEREVENT_SSL_ACCEPTING,
|
|
|
|
BEV_OPT_CLOSE_ON_FREE);
|
|
|
|
}
|
2015-11-06 10:13:13 +03:00
|
|
|
#endif
|
2020-09-06 15:33:32 +08:00
|
|
|
#ifdef EVENT__HAVE_MBEDTLS
|
|
|
|
static struct bufferevent *
|
|
|
|
https_mbedtls_bev(struct event_base *base, void *arg)
|
|
|
|
{
|
|
|
|
mbedtls_ssl_context *ssl = mbedtls_ssl_new(get_mbedtls_config(MBEDTLS_SSL_IS_SERVER));
|
|
|
|
return bufferevent_mbedtls_socket_new(
|
|
|
|
base, -1, ssl, BUFFEREVENT_SSL_ACCEPTING,
|
|
|
|
BEV_OPT_CLOSE_ON_FREE);
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-16 07:36:20 +00:00
|
|
|
static struct evhttp *
|
2017-11-04 19:13:28 +03:00
|
|
|
http_setup_gencb(ev_uint16_t *pport, struct event_base *base, int mask,
|
|
|
|
void (*cb)(struct evhttp_request *, void *), void *cbarg)
|
2006-01-22 05:08:50 +00:00
|
|
|
{
|
|
|
|
struct evhttp *myhttp;
|
|
|
|
|
|
|
|
/* Try a few different ports */
|
2007-08-19 02:41:23 +00:00
|
|
|
myhttp = evhttp_new(base);
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2015-11-05 10:58:41 +03:00
|
|
|
if (http_bind(myhttp, pport, mask) < 0)
|
2010-09-03 18:48:31 -04:00
|
|
|
return NULL;
|
2015-11-06 10:13:13 +03:00
|
|
|
#ifdef EVENT__HAVE_OPENSSL
|
2020-09-06 15:33:32 +08:00
|
|
|
if (mask & HTTP_OPENSSL) {
|
2015-11-05 10:58:41 +03:00
|
|
|
init_ssl();
|
|
|
|
evhttp_set_bevcb(myhttp, https_bev, NULL);
|
|
|
|
}
|
2015-11-06 10:13:13 +03:00
|
|
|
#endif
|
2020-09-06 15:33:32 +08:00
|
|
|
#ifdef EVENT__HAVE_MBEDTLS
|
|
|
|
if (mask & HTTP_MBEDTLS) {
|
|
|
|
evhttp_set_bevcb(myhttp, https_mbedtls_bev, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2017-11-04 19:13:28 +03:00
|
|
|
evhttp_set_gencb(myhttp, cb, cbarg);
|
|
|
|
|
2016-01-08 13:36:20 -08:00
|
|
|
/* add support for extended HTTP methods */
|
|
|
|
evhttp_set_ext_method_cmp(myhttp, ext_method_cb);
|
|
|
|
|
2006-02-13 02:22:48 +00:00
|
|
|
/* Register a callback for certain types of requests */
|
2016-03-25 11:04:51 +03:00
|
|
|
evhttp_set_cb(myhttp, "/test", http_basic_cb, myhttp);
|
2018-10-22 23:38:42 +03:00
|
|
|
evhttp_set_cb(myhttp, "/test nonconformant", http_basic_cb, myhttp);
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
evhttp_set_cb(myhttp, "/timeout", http_timeout_cb, myhttp);
|
2015-09-09 17:45:44 +03:00
|
|
|
evhttp_set_cb(myhttp, "/large", http_large_cb, base);
|
2010-11-03 13:55:20 -04:00
|
|
|
evhttp_set_cb(myhttp, "/chunked", http_chunked_cb, base);
|
2021-01-18 23:23:42 +03:00
|
|
|
evhttp_set_cb(myhttp, "/chunked_input", http_chunked_input_cb, base);
|
2010-11-03 13:55:20 -04:00
|
|
|
evhttp_set_cb(myhttp, "/streamed", http_chunked_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/postit", http_post_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/putit", http_put_cb, base);
|
2019-03-13 10:51:55 +03:00
|
|
|
evhttp_set_cb(myhttp, "/deleteit", http_genmethod_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/propfind", http_genmethod_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/proppatch", http_genmethod_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/mkcol", http_genmethod_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/lockit", http_genmethod_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/unlockit", http_genmethod_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/copyit", http_genmethod_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/moveit", http_genmethod_cb, base);
|
2016-01-08 13:36:20 -08:00
|
|
|
evhttp_set_cb(myhttp, "/custom", http_custom_cb, base);
|
2010-11-03 13:55:20 -04:00
|
|
|
evhttp_set_cb(myhttp, "/delay", http_delay_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/largedelay", http_large_delay_cb, base);
|
|
|
|
evhttp_set_cb(myhttp, "/badrequest", http_badreq_cb, base);
|
2014-01-05 20:35:46 -05:00
|
|
|
evhttp_set_cb(myhttp, "/oncomplete", http_on_complete_cb, base);
|
2010-11-03 13:55:20 -04:00
|
|
|
evhttp_set_cb(myhttp, "/", http_dispatcher_cb, base);
|
2006-01-22 05:08:50 +00:00
|
|
|
return (myhttp);
|
|
|
|
}
|
2017-11-04 19:13:28 +03:00
|
|
|
static struct evhttp *
|
|
|
|
http_setup(ev_uint16_t *pport, struct event_base *base, int mask)
|
|
|
|
{ return http_setup_gencb(pport, base, mask, NULL, NULL); }
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2007-09-20 19:08:20 +00:00
|
|
|
#ifndef NI_MAXSERV
|
|
|
|
#define NI_MAXSERV 1024
|
|
|
|
#endif
|
|
|
|
|
2010-11-03 14:38:45 -07:00
|
|
|
static evutil_socket_t
|
2014-12-13 19:42:42 +01:00
|
|
|
http_connect(const char *address, ev_uint16_t port)
|
2006-01-22 05:08:50 +00:00
|
|
|
{
|
|
|
|
/* Stupid code for connecting */
|
2011-01-31 16:37:27 -05:00
|
|
|
struct evutil_addrinfo ai, *aitop;
|
2006-01-22 05:08:50 +00:00
|
|
|
char strport[NI_MAXSERV];
|
2011-01-31 16:37:27 -05:00
|
|
|
|
2007-09-20 19:08:20 +00:00
|
|
|
struct sockaddr *sa;
|
2019-01-29 21:12:33 +03:00
|
|
|
size_t slen;
|
2010-03-05 12:47:46 -05:00
|
|
|
evutil_socket_t fd;
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-03-05 13:00:15 -05:00
|
|
|
memset(&ai, 0, sizeof(ai));
|
2006-01-22 05:08:50 +00:00
|
|
|
ai.ai_family = AF_INET;
|
|
|
|
ai.ai_socktype = SOCK_STREAM;
|
2010-03-05 13:00:15 -05:00
|
|
|
evutil_snprintf(strport, sizeof(strport), "%d", port);
|
2011-01-31 16:37:27 -05:00
|
|
|
if (evutil_getaddrinfo(address, strport, &ai, &aitop) != 0) {
|
2006-01-22 05:08:50 +00:00
|
|
|
event_warn("getaddrinfo");
|
|
|
|
return (-1);
|
|
|
|
}
|
2007-09-20 19:08:20 +00:00
|
|
|
sa = aitop->ai_addr;
|
|
|
|
slen = aitop->ai_addrlen;
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2006-01-22 05:08:50 +00:00
|
|
|
fd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (fd == -1)
|
|
|
|
event_err(1, "socket failed");
|
|
|
|
|
2007-12-28 00:34:05 +00:00
|
|
|
evutil_make_socket_nonblocking(fd);
|
2007-12-28 07:58:29 +00:00
|
|
|
if (connect(fd, sa, slen) == -1) {
|
2011-05-25 19:50:56 -04:00
|
|
|
#ifdef _WIN32
|
2008-05-12 17:16:47 +00:00
|
|
|
int tmp_err = WSAGetLastError();
|
|
|
|
if (tmp_err != WSAEINPROGRESS && tmp_err != WSAEINVAL &&
|
|
|
|
tmp_err != WSAEWOULDBLOCK)
|
|
|
|
event_err(1, "connect failed");
|
|
|
|
#else
|
2007-12-28 07:58:29 +00:00
|
|
|
if (errno != EINPROGRESS)
|
|
|
|
event_err(1, "connect failed");
|
2008-05-12 17:16:47 +00:00
|
|
|
#endif
|
2007-12-28 07:58:29 +00:00
|
|
|
}
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2011-01-31 16:37:27 -05:00
|
|
|
evutil_freeaddrinfo(aitop);
|
2006-01-22 05:08:50 +00:00
|
|
|
|
|
|
|
return (fd);
|
|
|
|
}
|
|
|
|
|
2010-10-21 12:48:13 -04:00
|
|
|
/* Helper: do a strcmp on the contents of buf and the string s. */
|
|
|
|
static int
|
|
|
|
evbuffer_datacmp(struct evbuffer *buf, const char *s)
|
|
|
|
{
|
|
|
|
size_t b_sz = evbuffer_get_length(buf);
|
|
|
|
size_t s_sz = strlen(s);
|
|
|
|
unsigned char *d;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (b_sz < s_sz)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
d = evbuffer_pullup(buf, s_sz);
|
2020-06-25 09:59:35 +03:00
|
|
|
if (!d)
|
|
|
|
d = (unsigned char *)"";
|
2010-10-21 12:48:13 -04:00
|
|
|
if ((r = memcmp(d, s, s_sz)))
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (b_sz > s_sz)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper: Return true iff buf contains s */
|
|
|
|
static int
|
|
|
|
evbuffer_contains(struct evbuffer *buf, const char *s)
|
|
|
|
{
|
|
|
|
struct evbuffer_ptr ptr;
|
|
|
|
ptr = evbuffer_search(buf, s, strlen(s), NULL);
|
|
|
|
return ptr.pos != -1;
|
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2006-01-22 05:08:50 +00:00
|
|
|
http_readcb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
2008-07-02 06:08:16 +00:00
|
|
|
const char *what = BASIC_REQUEST_BODY;
|
2010-11-03 13:55:20 -04:00
|
|
|
struct event_base *my_base = arg;
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2010-10-21 12:48:13 -04:00
|
|
|
if (evbuffer_contains(bufferevent_get_input(bev), what)) {
|
2006-01-22 05:08:50 +00:00
|
|
|
struct evhttp_request *req = evhttp_request_new(NULL, NULL);
|
2008-06-26 00:40:57 +00:00
|
|
|
enum message_read_status done;
|
2007-07-30 23:54:25 +00:00
|
|
|
|
2010-11-23 14:09:03 -07:00
|
|
|
/* req->kind = EVHTTP_RESPONSE; */
|
2012-02-29 15:07:33 -05:00
|
|
|
done = evhttp_parse_firstline_(req, bufferevent_get_input(bev));
|
2008-06-26 00:40:57 +00:00
|
|
|
if (done != ALL_DATA_READ)
|
|
|
|
goto out;
|
|
|
|
|
2012-02-29 15:07:33 -05:00
|
|
|
done = evhttp_parse_headers_(req, bufferevent_get_input(bev));
|
2008-06-26 00:40:57 +00:00
|
|
|
if (done != ALL_DATA_READ)
|
|
|
|
goto out;
|
2006-01-22 05:08:50 +00:00
|
|
|
|
|
|
|
if (done == 1 &&
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_find_header(evhttp_request_get_input_headers(req),
|
2006-01-22 05:08:50 +00:00
|
|
|
"Content-Type") != NULL)
|
|
|
|
test_ok++;
|
2008-06-26 00:40:57 +00:00
|
|
|
|
|
|
|
out:
|
2006-01-22 05:08:50 +00:00
|
|
|
evhttp_request_free(req);
|
2006-02-02 22:36:37 +00:00
|
|
|
bufferevent_disable(bev, EV_READ);
|
2010-11-03 14:13:20 -04:00
|
|
|
if (exit_base)
|
|
|
|
event_base_loopexit(exit_base, NULL);
|
2010-11-03 13:55:20 -04:00
|
|
|
else if (my_base)
|
|
|
|
event_base_loopexit(my_base, NULL);
|
2010-11-03 15:04:44 -04:00
|
|
|
else {
|
|
|
|
fprintf(stderr, "No way to exit loop!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-01-22 05:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2006-01-22 05:08:50 +00:00
|
|
|
http_writecb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
2010-10-21 12:48:13 -04:00
|
|
|
if (evbuffer_get_length(bufferevent_get_output(bev)) == 0) {
|
2006-01-22 05:08:50 +00:00
|
|
|
/* enable reading of the reply */
|
|
|
|
bufferevent_enable(bev, EV_READ);
|
|
|
|
test_ok++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2006-01-22 05:08:50 +00:00
|
|
|
http_errorcb(struct bufferevent *bev, short what, void *arg)
|
|
|
|
{
|
2015-11-05 19:12:58 +03:00
|
|
|
/** For ssl */
|
|
|
|
if (what & BEV_EVENT_CONNECTED)
|
|
|
|
return;
|
2006-01-22 05:08:50 +00:00
|
|
|
test_ok = -2;
|
2010-11-03 15:04:44 -04:00
|
|
|
event_base_loopexit(arg, NULL);
|
2006-01-22 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
2012-11-16 11:38:53 -05:00
|
|
|
static int found_multi = 0;
|
|
|
|
static int found_multi2 = 0;
|
|
|
|
|
2008-05-12 03:12:09 +00:00
|
|
|
static void
|
2006-01-22 05:08:50 +00:00
|
|
|
http_basic_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *evb = evbuffer_new();
|
2013-07-31 15:02:07 +00:00
|
|
|
struct evhttp_connection *evcon;
|
2010-11-03 15:14:29 -04:00
|
|
|
int empty = evhttp_find_header(evhttp_request_get_input_headers(req), "Empty") != NULL;
|
2018-04-24 02:22:58 +03:00
|
|
|
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
2008-07-02 06:08:16 +00:00
|
|
|
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2013-07-31 15:02:07 +00:00
|
|
|
evcon = evhttp_request_get_connection(req);
|
2016-03-25 11:04:51 +03:00
|
|
|
tt_assert(evhttp_connection_get_server(evcon) == arg);
|
2013-07-31 15:02:07 +00:00
|
|
|
|
2018-04-24 02:22:58 +03:00
|
|
|
{
|
|
|
|
const struct sockaddr *sa;
|
|
|
|
char addrbuf[128];
|
|
|
|
|
|
|
|
sa = evhttp_connection_get_addr(evcon);
|
|
|
|
tt_assert(sa);
|
|
|
|
|
|
|
|
if (sa->sa_family == AF_INET) {
|
|
|
|
evutil_format_sockaddr_port_((struct sockaddr *)sa, addrbuf, sizeof(addrbuf));
|
|
|
|
tt_assert(!strncmp(addrbuf, "127.0.0.1:", strlen("127.0.0.1:")));
|
|
|
|
} else if (sa->sa_family == AF_INET6) {
|
|
|
|
evutil_format_sockaddr_port_((struct sockaddr *)sa, addrbuf, sizeof(addrbuf));
|
|
|
|
tt_assert(!strncmp(addrbuf, "[::1]:", strlen("[::1]:")));
|
|
|
|
} else {
|
|
|
|
tt_fail_msg("Unsupported family");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-29 01:30:06 +00:00
|
|
|
/* For multi-line headers test */
|
|
|
|
{
|
|
|
|
const char *multi =
|
2012-11-16 11:38:53 -05:00
|
|
|
evhttp_find_header(evhttp_request_get_input_headers(req),"X-Multi");
|
2008-06-29 01:30:06 +00:00
|
|
|
if (multi) {
|
2012-11-16 11:38:53 -05:00
|
|
|
found_multi = !strcmp(multi,"aaaaaaaa a END");
|
2008-06-29 01:30:06 +00:00
|
|
|
if (strcmp("END", multi + strlen(multi) - 3) == 0)
|
|
|
|
test_ok++;
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req), "X-Last"))
|
2008-06-29 01:30:06 +00:00
|
|
|
test_ok++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-16 11:38:53 -05:00
|
|
|
{
|
|
|
|
const char *multi2 =
|
|
|
|
evhttp_find_header(evhttp_request_get_input_headers(req),"X-Multi-Extra-WS");
|
|
|
|
if (multi2) {
|
|
|
|
found_multi2 = !strcmp(multi2,"libevent 2.1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-02 04:22:48 +00:00
|
|
|
|
|
|
|
/* injecting a bad content-length */
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req), "X-Negative"))
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req),
|
2008-07-02 04:22:48 +00:00
|
|
|
"Content-Length", "-100");
|
|
|
|
|
2007-11-29 06:08:24 +00:00
|
|
|
/* allow sending of an empty reply */
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is fine",
|
|
|
|
!empty ? evb : NULL);
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2013-07-31 15:02:07 +00:00
|
|
|
end:
|
2006-01-22 05:08:50 +00:00
|
|
|
evbuffer_free(evb);
|
|
|
|
}
|
|
|
|
|
2019-01-29 21:12:33 +03:00
|
|
|
static void http_timeout_reply_cb(evutil_socket_t fd, short events, void *arg)
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
{
|
|
|
|
struct evhttp_request *req = arg;
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
|
|
|
|
test_ok++;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
http_timeout_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct timeval when = { 0, 100 };
|
|
|
|
event_base_once(exit_base, -1, EV_TIMEOUT,
|
|
|
|
http_timeout_reply_cb, req, &when);
|
|
|
|
}
|
|
|
|
|
2015-09-09 17:45:44 +03:00
|
|
|
static void
|
|
|
|
http_large_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *evb = evbuffer_new();
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 1<<20; ++i) {
|
|
|
|
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
|
|
|
}
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is fine", evb);
|
|
|
|
evbuffer_free(evb);
|
|
|
|
}
|
|
|
|
|
2008-06-26 00:40:57 +00:00
|
|
|
static char const* const CHUNKS[] = {
|
|
|
|
"This is funny",
|
|
|
|
"but not hilarious.",
|
|
|
|
"bwv 1052"
|
|
|
|
};
|
|
|
|
|
|
|
|
struct chunk_req_state {
|
2010-11-03 14:31:23 -04:00
|
|
|
struct event_base *base;
|
2008-06-26 00:40:57 +00:00
|
|
|
struct evhttp_request *req;
|
|
|
|
int i;
|
|
|
|
};
|
|
|
|
|
2008-05-12 03:12:09 +00:00
|
|
|
static void
|
2008-06-26 00:40:57 +00:00
|
|
|
http_chunked_trickle_cb(evutil_socket_t fd, short events, void *arg)
|
2008-04-29 02:33:27 +00:00
|
|
|
{
|
|
|
|
struct evbuffer *evb = evbuffer_new();
|
2008-06-26 00:40:57 +00:00
|
|
|
struct chunk_req_state *state = arg;
|
|
|
|
struct timeval when = { 0, 0 };
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2008-12-19 22:42:51 +00:00
|
|
|
evbuffer_add_printf(evb, "%s", CHUNKS[state->i]);
|
2008-06-26 00:40:57 +00:00
|
|
|
evhttp_send_reply_chunk(state->req, evb);
|
|
|
|
evbuffer_free(evb);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2010-10-14 13:16:41 -04:00
|
|
|
if (++state->i < (int) (sizeof(CHUNKS)/sizeof(CHUNKS[0]))) {
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_once(state->base, -1, EV_TIMEOUT,
|
2008-06-26 00:40:57 +00:00
|
|
|
http_chunked_trickle_cb, state, &when);
|
|
|
|
} else {
|
|
|
|
evhttp_send_reply_end(state->req);
|
|
|
|
free(state);
|
|
|
|
}
|
|
|
|
}
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2008-06-26 00:40:57 +00:00
|
|
|
static void
|
|
|
|
http_chunked_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct timeval when = { 0, 0 };
|
|
|
|
struct chunk_req_state *state = malloc(sizeof(struct chunk_req_state));
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2008-06-26 00:40:57 +00:00
|
|
|
memset(state, 0, sizeof(struct chunk_req_state));
|
|
|
|
state->req = req;
|
2010-11-03 14:31:23 -04:00
|
|
|
state->base = arg;
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2010-11-03 15:17:57 -04:00
|
|
|
if (strcmp(evhttp_request_get_uri(req), "/streamed") == 0) {
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Length", "39");
|
2010-02-18 17:08:50 -05:00
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-02-18 17:08:50 -05:00
|
|
|
/* generate a chunked/streamed reply */
|
2008-06-26 00:40:57 +00:00
|
|
|
evhttp_send_reply_start(req, HTTP_OK, "Everything is fine");
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2008-06-26 00:40:57 +00:00
|
|
|
/* but trickle it across several iterations to ensure we're not
|
|
|
|
* assuming it comes all at once */
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_once(arg, -1, EV_TIMEOUT, http_chunked_trickle_cb, state, &when);
|
2008-04-29 02:33:27 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 23:23:42 +03:00
|
|
|
static void
|
|
|
|
http_chunked_input_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *buf = evbuffer_new();
|
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
|
|
|
|
|
|
|
evbuffer_add_buffer(buf, evhttp_request_get_input_buffer(req));
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "OK", buf);
|
|
|
|
|
|
|
|
evbuffer_free(buf);
|
|
|
|
}
|
|
|
|
|
2015-11-05 10:58:41 +03:00
|
|
|
static struct bufferevent *
|
2020-06-25 21:56:31 +03:00
|
|
|
create_bev(struct event_base *base, evutil_socket_t fd, int ssl_mask, int flags_)
|
2015-11-05 10:58:41 +03:00
|
|
|
{
|
2020-06-25 21:56:31 +03:00
|
|
|
int flags = BEV_OPT_DEFER_CALLBACKS | flags_;
|
2015-11-06 10:13:13 +03:00
|
|
|
struct bufferevent *bev = NULL;
|
2015-11-05 10:58:41 +03:00
|
|
|
|
2016-12-07 03:07:59 +03:00
|
|
|
if (!ssl_mask) {
|
2015-11-06 02:24:28 +03:00
|
|
|
bev = bufferevent_socket_new(base, fd, flags);
|
2020-09-06 15:33:32 +08:00
|
|
|
} else if (ssl_mask & HTTP_OPENSSL){
|
2015-11-06 10:13:13 +03:00
|
|
|
#ifdef EVENT__HAVE_OPENSSL
|
2015-11-05 10:58:41 +03:00
|
|
|
SSL *ssl = SSL_new(get_ssl_ctx());
|
2016-12-07 03:07:59 +03:00
|
|
|
if (ssl_mask & HTTP_SSL_FILTER) {
|
|
|
|
struct bufferevent *underlying =
|
|
|
|
bufferevent_socket_new(base, fd, flags);
|
|
|
|
bev = bufferevent_openssl_filter_new(
|
|
|
|
base, underlying, ssl, BUFFEREVENT_SSL_CONNECTING, flags);
|
|
|
|
} else {
|
|
|
|
bev = bufferevent_openssl_socket_new(
|
|
|
|
base, fd, ssl, BUFFEREVENT_SSL_CONNECTING, flags);
|
|
|
|
}
|
2015-11-06 02:24:28 +03:00
|
|
|
bufferevent_openssl_set_allow_dirty_shutdown(bev, 1);
|
2020-09-06 15:33:32 +08:00
|
|
|
#endif
|
|
|
|
} else if (ssl_mask & HTTP_MBEDTLS) {
|
|
|
|
#ifdef EVENT__HAVE_MBEDTLS
|
|
|
|
mbedtls_ssl_context *ssl = mbedtls_ssl_new(get_mbedtls_config(MBEDTLS_SSL_IS_CLIENT));
|
|
|
|
if (ssl_mask & HTTP_SSL_FILTER) {
|
|
|
|
struct bufferevent *underlying =
|
|
|
|
bufferevent_socket_new(base, fd, flags);
|
|
|
|
bev = bufferevent_mbedtls_filter_new(
|
|
|
|
base, underlying, ssl, BUFFEREVENT_SSL_CONNECTING, flags);
|
|
|
|
} else {
|
|
|
|
bev = bufferevent_mbedtls_socket_new(
|
|
|
|
base, fd, ssl, BUFFEREVENT_SSL_CONNECTING, flags);
|
|
|
|
}
|
|
|
|
bufferevent_mbedtls_set_allow_dirty_shutdown(bev, 1);
|
2015-11-06 10:13:13 +03:00
|
|
|
#endif
|
2015-11-05 10:58:41 +03:00
|
|
|
}
|
2015-11-06 02:24:28 +03:00
|
|
|
|
|
|
|
return bev;
|
2015-11-05 10:58:41 +03:00
|
|
|
}
|
|
|
|
|
2018-11-02 23:43:57 +03:00
|
|
|
static void
|
|
|
|
http_half_writecb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
|
|
|
if (evbuffer_get_length(bufferevent_get_output(bev)) == 0) {
|
|
|
|
if (!test_ok) {
|
|
|
|
const char http_request[] = "host\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
}
|
|
|
|
/* enable reading of the reply */
|
|
|
|
bufferevent_enable(bev, EV_READ);
|
|
|
|
test_ok++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2018-10-22 23:38:42 +03:00
|
|
|
http_basic_test_impl(void *arg, int ssl, const char *request_line)
|
2006-01-22 05:08:50 +00:00
|
|
|
{
|
2010-11-03 13:55:20 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2014-09-18 12:40:38 -04:00
|
|
|
struct bufferevent *bev = NULL;
|
2010-03-05 12:47:46 -05:00
|
|
|
evutil_socket_t fd;
|
2007-11-26 19:18:49 +00:00
|
|
|
const char *http_request;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0, port2 = 0;
|
2020-09-06 15:33:32 +08:00
|
|
|
int server_flags = ssl;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, server_flags);
|
2018-10-22 23:38:42 +03:00
|
|
|
struct evbuffer *out;
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2016-03-25 11:22:43 +03:00
|
|
|
exit_base = data->base;
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2008-05-04 22:21:29 +00:00
|
|
|
/* bind to a second socket */
|
2015-11-05 19:12:58 +03:00
|
|
|
if (http_bind(http, &port2, server_flags) == -1) {
|
2008-05-04 22:21:29 +00:00
|
|
|
fprintf(stdout, "FAILED (bind)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2006-01-22 05:08:50 +00:00
|
|
|
fd = http_connect("127.0.0.1", port);
|
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
|
2018-11-02 23:43:57 +03:00
|
|
|
bufferevent_setcb(bev, http_readcb, http_half_writecb,
|
2010-11-03 13:55:20 -04:00
|
|
|
http_errorcb, data->base);
|
2018-10-22 23:38:42 +03:00
|
|
|
out = bufferevent_get_output(bev);
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2008-08-19 11:26:47 +00:00
|
|
|
/* first half of the http request */
|
2018-10-22 23:38:42 +03:00
|
|
|
evbuffer_add_printf(out,
|
|
|
|
"%s\r\n"
|
|
|
|
"Host: some", request_line);
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2018-11-02 23:43:57 +03:00
|
|
|
test_ok = 0;
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2018-10-22 23:38:42 +03:00
|
|
|
tt_int_op(test_ok, ==, 3);
|
2008-05-04 22:21:29 +00:00
|
|
|
|
|
|
|
/* connect to the second port */
|
|
|
|
bufferevent_free(bev);
|
|
|
|
|
2010-09-03 18:48:31 -04:00
|
|
|
fd = http_connect("127.0.0.1", port2);
|
2008-05-04 22:21:29 +00:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
2010-11-03 13:55:20 -04:00
|
|
|
http_errorcb, data->base);
|
2018-10-22 23:38:42 +03:00
|
|
|
out = bufferevent_get_output(bev);
|
2008-05-04 22:21:29 +00:00
|
|
|
|
2018-10-22 23:38:42 +03:00
|
|
|
evbuffer_add_printf(out,
|
|
|
|
"%s\r\n"
|
2008-05-04 22:21:29 +00:00
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
2018-10-22 23:38:42 +03:00
|
|
|
"\r\n", request_line);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2018-11-02 23:43:57 +03:00
|
|
|
test_ok = 0;
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2018-11-02 23:43:57 +03:00
|
|
|
tt_int_op(test_ok, ==, 2);
|
2010-11-05 11:17:07 -07:00
|
|
|
|
|
|
|
/* Connect to the second port again. This time, send an absolute uri. */
|
2006-01-22 05:08:50 +00:00
|
|
|
bufferevent_free(bev);
|
|
|
|
|
2010-11-05 11:17:07 -07:00
|
|
|
fd = http_connect("127.0.0.1", port2);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-05 11:17:07 -07:00
|
|
|
/* Stupid thing to send a request */
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
|
2010-11-05 11:17:07 -07:00
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
|
|
|
http_errorcb, data->base);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"GET http://somehost.net/test HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
|
2018-11-02 23:43:57 +03:00
|
|
|
test_ok = 0;
|
2010-11-05 11:17:07 -07:00
|
|
|
event_base_dispatch(data->base);
|
2018-11-02 23:43:57 +03:00
|
|
|
tt_int_op(test_ok, ==, 2);
|
2010-11-05 11:17:07 -07:00
|
|
|
|
|
|
|
evhttp_free(http);
|
2018-11-02 23:43:57 +03:00
|
|
|
end:
|
2014-09-18 12:40:38 -04:00
|
|
|
if (bev)
|
|
|
|
bufferevent_free(bev);
|
2006-01-22 05:08:50 +00:00
|
|
|
}
|
2018-10-22 23:38:42 +03:00
|
|
|
static void http_basic_test(void *arg)\
|
|
|
|
{ http_basic_test_impl(arg, 0, "GET /test HTTP/1.1"); }
|
|
|
|
static void http_basic_trailing_space_test(void *arg)
|
|
|
|
{ http_basic_test_impl(arg, 0, "GET /test HTTP/1.1 "); }
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2014-01-05 20:35:46 -05:00
|
|
|
|
2008-05-12 03:12:09 +00:00
|
|
|
static void
|
|
|
|
http_delay_reply(evutil_socket_t fd, short what, void *arg)
|
|
|
|
{
|
|
|
|
struct evhttp_request *req = arg;
|
|
|
|
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
|
|
|
|
|
|
|
|
++test_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_delay_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
Remove compat/sys/_time.h
I've gone through everything that it declared to see where it was used,
and it seems that we probably don't need it anywhere.
Here's what it declared, and why I think we're okay dropping it.
o struct timeval {}
(Used all over, and we can't really get away with declaring it ourselves;
we need the same definition the system uses. If we can't find struct
timeval, we're pretty much sunk.)
o struct timespec {}
(Used in event.c, evdns.c, kqueue.c, evport.c. Of these,
kqueue.c and event.c include sys/_time.h. event.c conditions its use on
_EVENT_HAVE_CLOCK_GETTIME, and kqueue() only works if timespec is defined.)
o TIMEVAL_TO_TIMESPEC
(Used in kqueue.c, but every place with kqueue has sys/time.h)
o struct timezone {}
(event2/util.h has a forward declaration; only evutil.c references it and
doesn't look at its contents.)
o timerclear, timerisset, timercmp, timeradd, timersub
(Everything now uses the evutil_timer* variants.)
o ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF, struct itemerval
(These are only used in test/regress.c, which does not include _time.h)
o CLOCK_REALTIME
(Only used in evdns.c, which does not include _time.h)
o TIMESPEC_TO_TIMEVAL
o DST_*
o timespecclear, timespecisset, timespeccmp, timespecadd, timespecsub
o struct clockinfo {}
o CLOCK_VIRTUAL, CLOCK_PROF
o TIMER_RELTIME, TIMER_ABSTIME
(unused)
svn:r1494
2009-11-03 19:54:56 +00:00
|
|
|
evutil_timerclear(&tv);
|
2008-05-12 03:12:09 +00:00
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 200 * 1000;
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_once(arg, -1, EV_TIMEOUT, http_delay_reply, req, &tv);
|
2008-05-12 03:12:09 +00:00
|
|
|
}
|
|
|
|
|
2010-01-11 19:04:11 -05:00
|
|
|
static void
|
|
|
|
http_badreq_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *buf = evbuffer_new();
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", "text/xml; charset=UTF-8");
|
2010-01-11 19:04:11 -05:00
|
|
|
evbuffer_add_printf(buf, "Hello, %s!", "127.0.0.1");
|
|
|
|
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "OK", buf);
|
|
|
|
evbuffer_free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_badreq_errorcb(struct bufferevent *bev, short what, void *arg)
|
|
|
|
{
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called (what=%04x, arg=%p)", __func__, what, arg));
|
2010-01-11 19:04:11 -05:00
|
|
|
/* ignore */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_badreq_readcb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
|
|
|
const char *what = "Hello, 127.0.0.1";
|
|
|
|
const char *bad_request = "400 Bad Request";
|
|
|
|
|
2010-10-21 12:48:13 -04:00
|
|
|
if (evbuffer_contains(bufferevent_get_input(bev), bad_request)) {
|
|
|
|
TT_FAIL(("%s:bad request detected", __func__));
|
2010-01-11 19:04:11 -05:00
|
|
|
bufferevent_disable(bev, EV_READ);
|
2010-11-03 15:04:44 -04:00
|
|
|
event_base_loopexit(arg, NULL);
|
2010-01-11 19:04:11 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-21 12:48:13 -04:00
|
|
|
if (evbuffer_contains(bufferevent_get_input(bev), what)) {
|
2010-01-11 19:04:11 -05:00
|
|
|
struct evhttp_request *req = evhttp_request_new(NULL, NULL);
|
|
|
|
enum message_read_status done;
|
|
|
|
|
2010-11-23 14:09:03 -07:00
|
|
|
/* req->kind = EVHTTP_RESPONSE; */
|
2012-02-29 15:07:33 -05:00
|
|
|
done = evhttp_parse_firstline_(req, bufferevent_get_input(bev));
|
2010-01-11 19:04:11 -05:00
|
|
|
if (done != ALL_DATA_READ)
|
|
|
|
goto out;
|
|
|
|
|
2012-02-29 15:07:33 -05:00
|
|
|
done = evhttp_parse_headers_(req, bufferevent_get_input(bev));
|
2010-01-11 19:04:11 -05:00
|
|
|
if (done != ALL_DATA_READ)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (done == 1 &&
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_find_header(evhttp_request_get_input_headers(req),
|
2010-01-11 19:04:11 -05:00
|
|
|
"Content-Type") != NULL)
|
|
|
|
test_ok++;
|
|
|
|
|
|
|
|
out:
|
|
|
|
evhttp_request_free(req);
|
2010-10-21 12:48:13 -04:00
|
|
|
evbuffer_drain(bufferevent_get_input(bev), evbuffer_get_length(bufferevent_get_input(bev)));
|
2010-01-11 19:04:11 -05:00
|
|
|
}
|
|
|
|
|
2016-03-11 01:27:52 +03:00
|
|
|
shutdown(bufferevent_getfd(bev), EVUTIL_SHUT_WR);
|
2010-01-11 19:04:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-05 12:47:46 -05:00
|
|
|
http_badreq_successcb(evutil_socket_t fd, short what, void *arg)
|
2010-01-11 19:04:11 -05:00
|
|
|
{
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called (what=%04x, arg=%p)", __func__, what, arg));
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(exit_base, NULL);
|
2010-01-11 19:04:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 14:31:23 -04:00
|
|
|
http_bad_request_test(void *arg)
|
2010-01-11 19:04:11 -05:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-01-11 19:04:11 -05:00
|
|
|
struct timeval tv;
|
2010-03-13 00:55:39 -05:00
|
|
|
struct bufferevent *bev = NULL;
|
2019-01-29 21:12:33 +03:00
|
|
|
evutil_socket_t fd = EVUTIL_INVALID_SOCKET;
|
2010-01-11 19:04:11 -05:00
|
|
|
const char *http_request;
|
2010-09-03 21:03:25 -04:00
|
|
|
ev_uint16_t port=0, port2=0;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2010-01-11 19:04:11 -05:00
|
|
|
|
|
|
|
test_ok = 0;
|
2010-11-03 14:31:23 -04:00
|
|
|
exit_base = data->base;
|
2010-01-11 19:04:11 -05:00
|
|
|
|
|
|
|
/* bind to a second socket */
|
2013-01-27 02:17:02 +04:00
|
|
|
if (http_bind(http, &port2, 0) == -1)
|
2010-01-11 19:04:11 -05:00
|
|
|
TT_DIE(("Bind socket failed"));
|
|
|
|
|
|
|
|
/* NULL request test */
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2010-01-11 19:04:11 -05:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2010-11-03 14:31:23 -04:00
|
|
|
bev = bufferevent_socket_new(data->base, fd, 0);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev, http_badreq_readcb, http_writecb,
|
2010-11-03 14:31:23 -04:00
|
|
|
http_badreq_errorcb, data->base);
|
2010-01-11 19:04:11 -05:00
|
|
|
bufferevent_enable(bev, EV_READ);
|
|
|
|
|
|
|
|
/* real NULL request */
|
|
|
|
http_request = "";
|
|
|
|
|
2011-04-11 17:32:03 +02:00
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
|
2016-03-11 01:27:52 +03:00
|
|
|
shutdown(fd, EVUTIL_SHUT_WR);
|
2010-01-11 19:04:11 -05:00
|
|
|
timerclear(&tv);
|
|
|
|
tv.tv_usec = 10000;
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_once(data->base, -1, EV_TIMEOUT, http_badreq_successcb, bev, &tv);
|
2010-01-11 19:04:11 -05:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2010-01-11 19:04:11 -05:00
|
|
|
|
|
|
|
bufferevent_free(bev);
|
2010-04-14 15:42:57 -04:00
|
|
|
evutil_closesocket(fd);
|
2010-01-11 19:04:11 -05:00
|
|
|
|
|
|
|
if (test_ok != 0) {
|
|
|
|
fprintf(stdout, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Second answer (BAD REQUEST) on connection close */
|
|
|
|
|
|
|
|
/* connect to the second port */
|
2010-09-03 18:48:31 -04:00
|
|
|
fd = http_connect("127.0.0.1", port2);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2010-01-11 19:04:11 -05:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2010-11-03 14:31:23 -04:00
|
|
|
bev = bufferevent_socket_new(data->base, fd, 0);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev, http_badreq_readcb, http_writecb,
|
2010-11-03 14:31:23 -04:00
|
|
|
http_badreq_errorcb, data->base);
|
2010-01-11 19:04:11 -05:00
|
|
|
bufferevent_enable(bev, EV_READ);
|
|
|
|
|
|
|
|
/* first half of the http request */
|
|
|
|
http_request =
|
|
|
|
"GET /badrequest HTTP/1.0\r\n" \
|
|
|
|
"Connection: Keep-Alive\r\n" \
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
|
|
|
|
timerclear(&tv);
|
|
|
|
tv.tv_usec = 10000;
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_once(data->base, -1, EV_TIMEOUT, http_badreq_successcb, bev, &tv);
|
2010-01-11 19:04:11 -05:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2010-01-11 19:04:11 -05:00
|
|
|
|
|
|
|
tt_int_op(test_ok, ==, 2);
|
|
|
|
|
|
|
|
end:
|
|
|
|
evhttp_free(http);
|
2010-03-13 00:55:39 -05:00
|
|
|
if (bev)
|
|
|
|
bufferevent_free(bev);
|
2014-01-08 13:02:37 -05:00
|
|
|
if (fd >= 0)
|
|
|
|
evutil_closesocket(fd);
|
2010-01-11 19:04:11 -05:00
|
|
|
}
|
|
|
|
|
2008-12-19 22:42:51 +00:00
|
|
|
static struct evhttp_connection *delayed_client;
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_large_delay_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
Remove compat/sys/_time.h
I've gone through everything that it declared to see where it was used,
and it seems that we probably don't need it anywhere.
Here's what it declared, and why I think we're okay dropping it.
o struct timeval {}
(Used all over, and we can't really get away with declaring it ourselves;
we need the same definition the system uses. If we can't find struct
timeval, we're pretty much sunk.)
o struct timespec {}
(Used in event.c, evdns.c, kqueue.c, evport.c. Of these,
kqueue.c and event.c include sys/_time.h. event.c conditions its use on
_EVENT_HAVE_CLOCK_GETTIME, and kqueue() only works if timespec is defined.)
o TIMEVAL_TO_TIMESPEC
(Used in kqueue.c, but every place with kqueue has sys/time.h)
o struct timezone {}
(event2/util.h has a forward declaration; only evutil.c references it and
doesn't look at its contents.)
o timerclear, timerisset, timercmp, timeradd, timersub
(Everything now uses the evutil_timer* variants.)
o ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF, struct itemerval
(These are only used in test/regress.c, which does not include _time.h)
o CLOCK_REALTIME
(Only used in evdns.c, which does not include _time.h)
o TIMESPEC_TO_TIMEVAL
o DST_*
o timespecclear, timespecisset, timespeccmp, timespecadd, timespecsub
o struct clockinfo {}
o CLOCK_VIRTUAL, CLOCK_PROF
o TIMER_RELTIME, TIMER_ABSTIME
(unused)
svn:r1494
2009-11-03 19:54:56 +00:00
|
|
|
evutil_timerclear(&tv);
|
2012-01-24 14:33:10 -05:00
|
|
|
tv.tv_usec = 500000;
|
2008-12-19 22:42:51 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_once(arg, -1, EV_TIMEOUT, http_delay_reply, req, &tv);
|
2013-03-21 13:55:40 +04:00
|
|
|
evhttp_connection_fail_(delayed_client, EVREQ_HTTP_EOF);
|
2008-12-19 22:42:51 +00:00
|
|
|
}
|
|
|
|
|
2008-05-12 03:12:09 +00:00
|
|
|
static void
|
2019-03-13 10:51:55 +03:00
|
|
|
http_genmethod_cb(struct evhttp_request *req, void *arg)
|
2008-02-27 06:20:48 +00:00
|
|
|
{
|
2019-03-13 10:51:55 +03:00
|
|
|
const char *uri = evhttp_request_get_uri(req);
|
2008-02-27 06:20:48 +00:00
|
|
|
struct evbuffer *evb = evbuffer_new();
|
2010-11-03 15:14:29 -04:00
|
|
|
int empty = evhttp_find_header(evhttp_request_get_input_headers(req), "Empty") != NULL;
|
2019-03-13 10:51:55 +03:00
|
|
|
enum evhttp_cmd_type method;
|
|
|
|
|
|
|
|
if (!strcmp(uri, "/deleteit"))
|
|
|
|
method = EVHTTP_REQ_DELETE;
|
|
|
|
else if (!strcmp(uri, "/propfind"))
|
|
|
|
method = EVHTTP_REQ_PROPFIND;
|
|
|
|
else if (!strcmp(uri, "/proppatch"))
|
|
|
|
method = EVHTTP_REQ_PROPPATCH;
|
|
|
|
else if (!strcmp(uri, "/mkcol"))
|
|
|
|
method = EVHTTP_REQ_MKCOL;
|
|
|
|
else if (!strcmp(uri, "/lockit"))
|
|
|
|
method = EVHTTP_REQ_LOCK;
|
|
|
|
else if (!strcmp(uri, "/unlockit"))
|
|
|
|
method = EVHTTP_REQ_UNLOCK;
|
|
|
|
else if (!strcmp(uri, "/copyit"))
|
|
|
|
method = EVHTTP_REQ_COPY;
|
|
|
|
else if (!strcmp(uri, "/moveit"))
|
|
|
|
method = EVHTTP_REQ_MOVE;
|
|
|
|
else {
|
|
|
|
fprintf(stdout, "FAILED (unexpected path)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/* Expecting correct request method */
|
|
|
|
if (evhttp_request_get_command(req) != method) {
|
2008-02-27 06:20:48 +00:00
|
|
|
fprintf(stdout, "FAILED (delete type)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
2008-07-02 06:08:16 +00:00
|
|
|
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
2008-02-27 06:20:48 +00:00
|
|
|
|
|
|
|
/* allow sending of an empty reply */
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is fine",
|
|
|
|
!empty ? evb : NULL);
|
|
|
|
|
|
|
|
evbuffer_free(evb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-13 10:51:55 +03:00
|
|
|
http_genmethod_test(void *arg, enum evhttp_cmd_type method, const char *name, const char *path)
|
2008-02-27 06:20:48 +00:00
|
|
|
{
|
2010-11-03 13:55:20 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2008-02-27 06:20:48 +00:00
|
|
|
struct bufferevent *bev;
|
2019-03-13 10:51:55 +03:00
|
|
|
struct evbuffer *evb;
|
2019-01-29 21:12:33 +03:00
|
|
|
evutil_socket_t fd = EVUTIL_INVALID_SOCKET;
|
2010-09-03 22:00:25 -04:00
|
|
|
ev_uint16_t port = 0;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2008-02-27 06:20:48 +00:00
|
|
|
|
2016-03-25 11:22:43 +03:00
|
|
|
exit_base = data->base;
|
2008-02-27 06:20:48 +00:00
|
|
|
test_ok = 0;
|
2016-03-25 11:22:43 +03:00
|
|
|
|
2014-09-18 11:54:04 -04:00
|
|
|
tt_assert(http);
|
2008-02-27 06:20:48 +00:00
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2008-02-27 06:20:48 +00:00
|
|
|
|
2019-03-13 10:51:55 +03:00
|
|
|
evhttp_set_allowed_methods(http, method);
|
|
|
|
|
2008-02-27 06:20:48 +00:00
|
|
|
/* Stupid thing to send a request */
|
2010-11-03 13:55:20 -04:00
|
|
|
bev = bufferevent_socket_new(data->base, fd, 0);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
2010-11-03 13:55:20 -04:00
|
|
|
http_errorcb, data->base);
|
2019-03-13 10:51:55 +03:00
|
|
|
evb = bufferevent_get_output(bev);
|
|
|
|
evbuffer_add_printf(
|
|
|
|
evb,
|
|
|
|
"%s %s HTTP/1.1\r\n"
|
2008-02-27 06:20:48 +00:00
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
2019-03-13 10:51:55 +03:00
|
|
|
"\r\n"
|
|
|
|
"body", name, path);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-02-27 06:20:48 +00:00
|
|
|
|
|
|
|
bufferevent_free(bev);
|
2010-04-14 15:42:57 -04:00
|
|
|
evutil_closesocket(fd);
|
2019-01-29 21:12:33 +03:00
|
|
|
fd = EVUTIL_INVALID_SOCKET;
|
2008-02-27 06:20:48 +00:00
|
|
|
|
|
|
|
evhttp_free(http);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(test_ok, ==, 2);
|
|
|
|
end:
|
2014-01-08 13:02:37 -05:00
|
|
|
if (fd >= 0)
|
|
|
|
evutil_closesocket(fd);
|
2008-02-27 06:20:48 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 13:36:20 -08:00
|
|
|
/*
|
|
|
|
* HTTP CUSTOM test, just piggyback on the basic test
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
http_custom_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *evb = evbuffer_new();
|
|
|
|
int empty = evhttp_find_header(evhttp_request_get_input_headers(req), "Empty") != NULL;
|
|
|
|
|
|
|
|
/* Expecting a CUSTOM request */
|
|
|
|
if (evhttp_request_get_command(req) != EVHTTP_REQ_CUSTOM) {
|
|
|
|
fprintf(stdout, "FAILED (custom type)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
|
|
|
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
|
|
|
|
|
|
|
/* allow sending of an empty reply */
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is fine",
|
|
|
|
!empty ? evb : NULL);
|
|
|
|
|
|
|
|
evbuffer_free(evb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_custom_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
struct bufferevent *bev;
|
|
|
|
evutil_socket_t fd = -1;
|
|
|
|
const char *http_request;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp *http;
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
http = http_setup(&port, data->base, 0);
|
|
|
|
/* Allow custom */
|
|
|
|
evhttp_set_allowed_methods(http, EVHTTP_REQ_CUSTOM);
|
|
|
|
|
|
|
|
tt_assert(http);
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
|
|
|
tt_int_op(fd, >=, 0);
|
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
|
|
|
bev = bufferevent_socket_new(data->base, fd, 0);
|
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
|
|
|
http_errorcb, data->base);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"CUSTOM /custom HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
bufferevent_free(bev);
|
|
|
|
evutil_closesocket(fd);
|
|
|
|
fd = -1;
|
|
|
|
|
|
|
|
evhttp_free(http);
|
|
|
|
|
|
|
|
tt_int_op(test_ok, ==, 2);
|
|
|
|
end:
|
|
|
|
if (fd >= 0)
|
|
|
|
evutil_closesocket(fd);
|
|
|
|
}
|
|
|
|
|
2019-03-13 10:51:55 +03:00
|
|
|
static void
|
|
|
|
http_delete_test(void *arg)
|
|
|
|
{
|
|
|
|
http_genmethod_test(arg, EVHTTP_REQ_DELETE, "DELETE", "/deleteit");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_propfind_test(void *arg)
|
|
|
|
{
|
|
|
|
http_genmethod_test(arg, EVHTTP_REQ_PROPFIND, "PROPFIND", "/propfind");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_proppatch_test(void *arg)
|
|
|
|
{
|
|
|
|
http_genmethod_test(arg, EVHTTP_REQ_PROPPATCH, "PROPPATCH", "/proppatch");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_mkcol_test(void *arg)
|
|
|
|
{
|
|
|
|
http_genmethod_test(arg, EVHTTP_REQ_MKCOL, "MKCOL", "/mkcol");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_lock_test(void *arg)
|
|
|
|
{
|
|
|
|
http_genmethod_test(arg, EVHTTP_REQ_LOCK, "LOCK", "/lockit");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_unlock_test(void *arg)
|
|
|
|
{
|
|
|
|
http_genmethod_test(arg, EVHTTP_REQ_UNLOCK, "UNLOCK", "/unlockit");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_copy_test(void *arg)
|
|
|
|
{
|
|
|
|
http_genmethod_test(arg, EVHTTP_REQ_COPY, "COPY", "/copyit");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_move_test(void *arg)
|
|
|
|
{
|
|
|
|
http_genmethod_test(arg, EVHTTP_REQ_MOVE, "MOVE", "/moveit");
|
|
|
|
}
|
|
|
|
|
2014-01-05 20:35:46 -05:00
|
|
|
static void
|
|
|
|
http_sent_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2014-01-08 12:46:09 -05:00
|
|
|
ev_uintptr_t val = (ev_uintptr_t)arg;
|
2014-01-06 21:19:15 -05:00
|
|
|
struct evbuffer *b;
|
2014-01-05 20:35:46 -05:00
|
|
|
|
|
|
|
if (val != 0xDEADBEEF) {
|
|
|
|
fprintf(stdout, "FAILED on_complete_cb argument\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2014-01-06 21:19:15 -05:00
|
|
|
b = evhttp_request_get_output_buffer(req);
|
|
|
|
if (evbuffer_get_length(b) != 0) {
|
|
|
|
fprintf(stdout, "FAILED on_complete_cb output buffer not written\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
2014-01-05 20:35:46 -05:00
|
|
|
|
|
|
|
++test_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_on_complete_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *evb = evbuffer_new();
|
|
|
|
|
|
|
|
evhttp_request_set_on_complete_cb(req, http_sent_cb, (void *)0xDEADBEEF);
|
|
|
|
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
2014-01-05 20:35:46 -05:00
|
|
|
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
|
|
|
|
|
|
|
/* allow sending of an empty reply */
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is fine", evb);
|
|
|
|
|
|
|
|
evbuffer_free(evb);
|
|
|
|
|
|
|
|
++test_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_on_complete_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
struct bufferevent *bev;
|
2019-01-29 21:12:33 +03:00
|
|
|
evutil_socket_t fd = EVUTIL_INVALID_SOCKET;
|
2014-01-05 20:35:46 -05:00
|
|
|
const char *http_request;
|
|
|
|
ev_uint16_t port = 0;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2014-01-05 20:35:46 -05:00
|
|
|
|
2016-03-25 11:22:43 +03:00
|
|
|
exit_base = data->base;
|
2014-01-05 20:35:46 -05:00
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2014-01-05 20:35:46 -05:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
|
|
|
bev = bufferevent_socket_new(data->base, fd, 0);
|
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
|
|
|
http_errorcb, data->base);
|
|
|
|
|
|
|
|
http_request =
|
2014-01-06 21:19:15 -05:00
|
|
|
"GET /oncomplete HTTP/1.1\r\n"
|
2014-01-05 20:35:46 -05:00
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
bufferevent_free(bev);
|
|
|
|
|
|
|
|
evhttp_free(http);
|
|
|
|
|
|
|
|
tt_int_op(test_ok, ==, 4);
|
|
|
|
end:
|
2014-01-08 13:02:37 -05:00
|
|
|
if (fd >= 0)
|
|
|
|
evutil_closesocket(fd);
|
2014-01-05 20:35:46 -05:00
|
|
|
}
|
|
|
|
|
2010-11-04 12:41:13 -04:00
|
|
|
static void
|
|
|
|
http_allowed_methods_eventcb(struct bufferevent *bev, short what, void *arg)
|
|
|
|
{
|
|
|
|
char **output = arg;
|
|
|
|
if ((what & (BEV_EVENT_ERROR|BEV_EVENT_EOF))) {
|
|
|
|
char buf[4096];
|
|
|
|
int n;
|
|
|
|
n = evbuffer_remove(bufferevent_get_input(bev), buf,
|
|
|
|
sizeof(buf)-1);
|
|
|
|
if (n >= 0) {
|
|
|
|
buf[n]='\0';
|
|
|
|
if (*output)
|
|
|
|
free(*output);
|
|
|
|
*output = strdup(buf);
|
|
|
|
}
|
|
|
|
event_base_loopexit(exit_base, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_allowed_methods_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
2016-01-08 13:36:20 -08:00
|
|
|
struct bufferevent *bev1, *bev2, *bev3, *bev4;
|
|
|
|
evutil_socket_t fd1=-1, fd2=-1, fd3=-1, fd4=-1;
|
2010-11-04 12:41:13 -04:00
|
|
|
const char *http_request;
|
2016-01-08 13:36:20 -08:00
|
|
|
char *result1=NULL, *result2=NULL, *result3=NULL, *result4=NULL;
|
2010-11-04 12:41:13 -04:00
|
|
|
ev_uint16_t port = 0;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2010-11-04 12:41:13 -04:00
|
|
|
|
|
|
|
exit_base = data->base;
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
fd1 = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd1 != EVUTIL_INVALID_SOCKET);
|
2010-11-04 12:41:13 -04:00
|
|
|
|
2016-01-08 13:36:20 -08:00
|
|
|
/* GET is out; PATCH & CUSTOM are in. */
|
|
|
|
evhttp_set_allowed_methods(http, EVHTTP_REQ_PATCH | EVHTTP_REQ_CUSTOM);
|
2010-11-04 12:41:13 -04:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
|
|
|
bev1 = bufferevent_socket_new(data->base, fd1, 0);
|
|
|
|
bufferevent_enable(bev1, EV_READ|EV_WRITE);
|
|
|
|
bufferevent_setcb(bev1, NULL, NULL,
|
|
|
|
http_allowed_methods_eventcb, &result1);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"GET /index.html HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev1, http_request, strlen(http_request));
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
fd2 = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd2 != EVUTIL_INVALID_SOCKET);
|
2010-11-04 12:41:13 -04:00
|
|
|
|
|
|
|
bev2 = bufferevent_socket_new(data->base, fd2, 0);
|
|
|
|
bufferevent_enable(bev2, EV_READ|EV_WRITE);
|
|
|
|
bufferevent_setcb(bev2, NULL, NULL,
|
|
|
|
http_allowed_methods_eventcb, &result2);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"PATCH /test HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev2, http_request, strlen(http_request));
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
fd3 = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd3 != EVUTIL_INVALID_SOCKET);
|
2010-11-04 12:41:13 -04:00
|
|
|
|
|
|
|
bev3 = bufferevent_socket_new(data->base, fd3, 0);
|
|
|
|
bufferevent_enable(bev3, EV_READ|EV_WRITE);
|
|
|
|
bufferevent_setcb(bev3, NULL, NULL,
|
|
|
|
http_allowed_methods_eventcb, &result3);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"FLOOP /test HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev3, http_request, strlen(http_request));
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
2016-01-08 13:36:20 -08:00
|
|
|
fd4 = http_connect("127.0.0.1", port);
|
|
|
|
tt_int_op(fd4, >=, 0);
|
|
|
|
|
|
|
|
bev4 = bufferevent_socket_new(data->base, fd4, 0);
|
|
|
|
bufferevent_enable(bev4, EV_READ|EV_WRITE);
|
|
|
|
bufferevent_setcb(bev4, NULL, NULL,
|
|
|
|
http_allowed_methods_eventcb, &result4);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"CUSTOM /test HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev4, http_request, strlen(http_request));
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
2010-11-04 12:41:13 -04:00
|
|
|
bufferevent_free(bev1);
|
|
|
|
bufferevent_free(bev2);
|
|
|
|
bufferevent_free(bev3);
|
2016-01-08 13:36:20 -08:00
|
|
|
bufferevent_free(bev4);
|
2010-11-04 12:41:13 -04:00
|
|
|
|
|
|
|
evhttp_free(http);
|
|
|
|
|
|
|
|
/* Method known but disallowed */
|
|
|
|
tt_assert(result1);
|
|
|
|
tt_assert(!strncmp(result1, "HTTP/1.1 501 ", strlen("HTTP/1.1 501 ")));
|
|
|
|
|
|
|
|
/* Method known and allowed */
|
|
|
|
tt_assert(result2);
|
|
|
|
tt_assert(!strncmp(result2, "HTTP/1.1 200 ", strlen("HTTP/1.1 200 ")));
|
|
|
|
|
|
|
|
/* Method unknown */
|
|
|
|
tt_assert(result3);
|
|
|
|
tt_assert(!strncmp(result3, "HTTP/1.1 501 ", strlen("HTTP/1.1 501 ")));
|
|
|
|
|
2016-01-08 13:36:20 -08:00
|
|
|
/* Custom method (and allowed) */
|
|
|
|
tt_assert(result4);
|
|
|
|
tt_assert(!strncmp(result4, "HTTP/1.1 200 ", strlen("HTTP/1.1 200 ")));
|
|
|
|
|
2010-11-04 12:41:13 -04:00
|
|
|
end:
|
|
|
|
if (result1)
|
|
|
|
free(result1);
|
|
|
|
if (result2)
|
|
|
|
free(result2);
|
|
|
|
if (result3)
|
|
|
|
free(result3);
|
2016-01-08 13:36:20 -08:00
|
|
|
if (result4)
|
|
|
|
free(result4);
|
2014-01-08 13:02:37 -05:00
|
|
|
if (fd1 >= 0)
|
|
|
|
evutil_closesocket(fd1);
|
|
|
|
if (fd2 >= 0)
|
|
|
|
evutil_closesocket(fd2);
|
|
|
|
if (fd3 >= 0)
|
|
|
|
evutil_closesocket(fd3);
|
2016-01-08 13:36:20 -08:00
|
|
|
if (fd4 >= 0)
|
|
|
|
evutil_closesocket(fd4);
|
2010-11-04 12:41:13 -04:00
|
|
|
}
|
|
|
|
|
2015-09-09 19:15:18 +03:00
|
|
|
static void http_request_no_action_done(struct evhttp_request *, void *);
|
2008-05-07 01:52:24 +00:00
|
|
|
static void http_request_done(struct evhttp_request *, void *);
|
|
|
|
static void http_request_empty_done(struct evhttp_request *, void *);
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2014-03-27 00:44:51 +04:00
|
|
|
http_connection_test_(struct basic_test_data *data, int persistent,
|
2016-11-19 15:54:52 +03:00
|
|
|
const char *address, struct evdns_base *dnsbase, int ipv6, int family,
|
|
|
|
int ssl)
|
2006-01-22 05:08:50 +00:00
|
|
|
{
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2006-01-22 05:08:50 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
2006-07-17 00:33:57 +00:00
|
|
|
struct evhttp_request *req = NULL;
|
2016-11-19 15:54:52 +03:00
|
|
|
struct evhttp *http;
|
|
|
|
|
|
|
|
int mask = 0;
|
|
|
|
if (ipv6)
|
|
|
|
mask |= HTTP_BIND_IPV6;
|
|
|
|
if (ssl)
|
2020-09-06 15:33:32 +08:00
|
|
|
mask |= HTTP_OPENSSL;
|
2016-11-19 15:54:52 +03:00
|
|
|
|
|
|
|
http = http_setup(&port, data->base, mask);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2006-01-22 05:08:50 +00:00
|
|
|
test_ok = 0;
|
2014-03-12 18:13:19 -04:00
|
|
|
if (!http && ipv6) {
|
|
|
|
tt_skip();
|
|
|
|
}
|
|
|
|
tt_assert(http);
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2016-01-08 13:36:20 -08:00
|
|
|
evhttp_set_allowed_methods(http, EVHTTP_REQ_GET | EVHTTP_REQ_CUSTOM);
|
|
|
|
|
2016-11-19 15:54:52 +03:00
|
|
|
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);
|
|
|
|
}
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2014-03-27 00:44:51 +04:00
|
|
|
evhttp_connection_set_family(evcon, family);
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
tt_assert(evhttp_connection_get_base(evcon) == data->base);
|
2010-10-21 12:19:28 -04:00
|
|
|
|
2010-11-03 14:13:20 -04:00
|
|
|
exit_base = data->base;
|
2013-07-31 15:02:07 +00:00
|
|
|
|
|
|
|
tt_assert(evhttp_connection_get_server(evcon) == NULL);
|
|
|
|
|
2016-01-08 13:36:20 -08:00
|
|
|
/* add support for CUSTOM method */
|
|
|
|
evhttp_connection_set_ext_method_cmp(evcon, ext_method_cb);
|
|
|
|
|
2006-02-27 02:27:37 +00:00
|
|
|
/*
|
|
|
|
* At this point, we want to schedule a request to the HTTP
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
2008-07-02 06:08:16 +00:00
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
2006-01-22 05:08:50 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2006-07-17 00:33:57 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
2006-02-13 02:22:48 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
2006-01-22 05:08:50 +00:00
|
|
|
fprintf(stdout, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-07-17 00:33:57 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2006-07-17 00:33:57 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(test_ok);
|
2006-11-17 07:45:42 +00:00
|
|
|
|
|
|
|
/* try to make another request over the same connection */
|
|
|
|
test_ok = 0;
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-07-02 06:08:16 +00:00
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
2006-11-17 07:45:42 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2006-11-17 07:45:42 +00:00
|
|
|
|
2009-01-27 21:10:31 +00:00
|
|
|
/*
|
2006-11-18 03:43:26 +00:00
|
|
|
* if our connections are not supposed to be persistent; request
|
|
|
|
* a close from the server.
|
|
|
|
*/
|
|
|
|
if (!persistent)
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Connection", "close");
|
2006-11-18 03:43:26 +00:00
|
|
|
|
2006-11-17 07:45:42 +00:00
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("couldn't make request");
|
2006-11-17 07:45:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2006-11-17 07:45:42 +00:00
|
|
|
|
2007-11-29 06:08:24 +00:00
|
|
|
/* make another request: request empty reply */
|
|
|
|
test_ok = 0;
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
req = evhttp_request_new(http_request_empty_done, data->base);
|
2007-11-29 06:08:24 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Empty", "itis");
|
2007-11-29 06:08:24 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2007-11-29 06:08:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2007-11-29 06:08:24 +00:00
|
|
|
|
2016-01-08 13:36:20 -08:00
|
|
|
/* make a CUSTOM request */
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_empty_done, data->base);
|
|
|
|
|
|
|
|
/* our CUSTOM method doesn't have Body */
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Empty", "itis");
|
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_CUSTOM, "/test") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_connection_test(void *arg)
|
2009-01-30 17:44:13 +00:00
|
|
|
{
|
2016-11-19 15:54:52 +03:00
|
|
|
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_UNSPEC, 0);
|
2009-01-30 17:44:13 +00:00
|
|
|
}
|
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_persist_connection_test(void *arg)
|
2009-01-30 17:44:13 +00:00
|
|
|
{
|
2016-11-19 15:54:52 +03:00
|
|
|
http_connection_test_(arg, 1, "127.0.0.1", NULL, 0, AF_UNSPEC, 0);
|
2006-01-22 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
2010-01-14 17:05:00 -08:00
|
|
|
static struct regress_dns_server_table search_table[] = {
|
2015-10-09 01:50:05 +03:00
|
|
|
{ "localhost", "A", "127.0.0.1", 0, 0 },
|
|
|
|
{ NULL, NULL, NULL, 0, 0 }
|
2010-01-14 17:05:00 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_connection_async_test(void *arg)
|
2010-01-14 17:05:00 -08:00
|
|
|
{
|
2010-11-03 13:55:20 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2010-01-14 17:05:00 -08:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
|
|
|
struct evdns_base *dns_base = NULL;
|
|
|
|
ev_uint16_t portnum = 0;
|
|
|
|
char address[64];
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2010-01-14 17:05:00 -08:00
|
|
|
|
2010-11-03 14:13:20 -04:00
|
|
|
exit_base = data->base;
|
2020-05-21 12:46:20 +03:00
|
|
|
tt_assert(regress_dnsserver(data->base, &portnum, search_table, NULL));
|
2010-01-14 17:05:00 -08:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
dns_base = evdns_base_new(data->base, 0/* init name servers */);
|
2010-01-14 17:05:00 -08:00
|
|
|
tt_assert(dns_base);
|
|
|
|
|
|
|
|
/* Add ourself as the only nameserver, and make sure we really are
|
|
|
|
* the only nameserver. */
|
2010-03-05 12:47:46 -05:00
|
|
|
evutil_snprintf(address, sizeof(address), "127.0.0.1:%d", portnum);
|
2010-01-14 17:05:00 -08:00
|
|
|
evdns_base_nameserver_ip_add(dns_base, address);
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, dns_base, "127.0.0.1", port);
|
2010-01-14 17:05:00 -08:00
|
|
|
tt_assert(evcon);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we want to schedule a request to the HTTP
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2010-01-14 17:05:00 -08:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
|
|
|
fprintf(stdout, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2010-01-14 17:05:00 -08:00
|
|
|
|
|
|
|
tt_assert(test_ok);
|
|
|
|
|
|
|
|
/* try to make another request over the same connection */
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2010-01-14 17:05:00 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if our connections are not supposed to be persistent; request
|
|
|
|
* a close from the server.
|
|
|
|
*/
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Connection", "close");
|
2010-01-14 17:05:00 -08:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
|
|
|
tt_abort_msg("couldn't make request");
|
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2010-01-14 17:05:00 -08:00
|
|
|
|
|
|
|
/* make another request: request empty reply */
|
|
|
|
test_ok = 0;
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
req = evhttp_request_new(http_request_empty_done, data->base);
|
2010-01-14 17:05:00 -08:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Empty", "itis");
|
2010-01-14 17:05:00 -08:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2010-01-14 17:05:00 -08:00
|
|
|
|
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2010-02-18 17:41:15 -05:00
|
|
|
if (dns_base)
|
|
|
|
evdns_base_free(dns_base, 0);
|
2010-01-14 17:05:00 -08:00
|
|
|
regress_clean_dnsserver();
|
|
|
|
}
|
|
|
|
|
2014-10-29 03:40:44 -04:00
|
|
|
static void
|
|
|
|
http_autofree_connection_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req[2] = { NULL };
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2020-05-19 01:05:50 +03:00
|
|
|
size_t i;
|
2014-10-29 03:40:44 -04:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
|
|
|
tt_assert(evcon);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we want to schedule two request to the HTTP
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
req[0] = evhttp_request_new(http_request_empty_done, data->base);
|
|
|
|
req[1] = evhttp_request_new(http_request_empty_done, data->base);
|
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2020-05-19 01:05:50 +03:00
|
|
|
for (i = 0; i < ARRAY_SIZE(req); ++i) {
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req[i]), "Host", "somehost");
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req[i]), "Connection", "close");
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req[i]), "Empty", "itis");
|
2014-10-29 03:40:44 -04:00
|
|
|
|
2020-05-25 02:06:32 +03:00
|
|
|
if (evhttp_make_request(evcon, req[i], EVHTTP_REQ_GET, "/test") == -1) {
|
|
|
|
tt_abort_msg("couldn't make request");
|
|
|
|
}
|
2014-10-29 03:40:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell libevent to free the connection when the request completes
|
|
|
|
* We then set the evcon pointer to NULL since we don't want to free it
|
|
|
|
* when this function ends.
|
|
|
|
*/
|
|
|
|
evhttp_connection_free_on_completion(evcon);
|
|
|
|
evcon = NULL;
|
|
|
|
|
2020-05-25 02:06:32 +03:00
|
|
|
for (i = 0; i < ARRAY_SIZE(req); ++i)
|
|
|
|
event_base_dispatch(data->base);
|
2014-10-29 03:40:44 -04:00
|
|
|
|
|
|
|
/* at this point, the http server should have no connection */
|
|
|
|
tt_assert(TAILQ_FIRST(&http->connections) == NULL);
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
|
|
|
|
2008-05-12 03:12:09 +00:00
|
|
|
static void
|
|
|
|
http_request_never_call(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
static void
|
|
|
|
http_failed_request_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
tt_assert(!req);
|
|
|
|
end:
|
|
|
|
event_base_loopexit(arg, NULL);
|
|
|
|
}
|
2016-03-24 20:29:25 +03:00
|
|
|
#ifndef _WIN32
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
static void
|
|
|
|
http_timed_out_request_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
tt_assert(req);
|
|
|
|
tt_int_op(evhttp_request_get_response_code(req), !=, HTTP_OK);
|
|
|
|
end:
|
|
|
|
event_base_loopexit(arg, NULL);
|
|
|
|
}
|
2016-03-24 20:29:25 +03:00
|
|
|
#endif
|
2008-05-12 03:12:09 +00:00
|
|
|
|
2016-03-13 13:05:25 +03:00
|
|
|
static void
|
|
|
|
http_request_error_cb_with_cancel(enum evhttp_request_error error, void *arg)
|
|
|
|
{
|
|
|
|
if (error != EVREQ_HTTP_REQUEST_CANCEL) {
|
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
test_ok = 1;
|
|
|
|
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
evutil_timerclear(&tv);
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 500 * 1000;
|
|
|
|
event_base_loopexit(exit_base, &tv);
|
|
|
|
}
|
|
|
|
}
|
2008-05-12 03:12:09 +00:00
|
|
|
static void
|
|
|
|
http_do_cancel(evutil_socket_t fd, short what, void *arg)
|
|
|
|
{
|
|
|
|
struct evhttp_request *req = arg;
|
|
|
|
evhttp_cancel_request(req);
|
|
|
|
++test_ok;
|
|
|
|
}
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
static void
|
|
|
|
http_no_write(struct evbuffer *buffer, const struct evbuffer_cb_info *info, void *arg)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
http_free_evcons(struct evhttp_connection **evcons)
|
|
|
|
{
|
2016-03-24 14:11:10 +03:00
|
|
|
struct evhttp_connection *evcon, **orig = evcons;
|
|
|
|
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
if (!evcons)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((evcon = *evcons++)) {
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
}
|
|
|
|
free(orig);
|
|
|
|
}
|
|
|
|
/** fill the backlog to force server drop packages for timeouts */
|
|
|
|
static struct evhttp_connection **
|
|
|
|
http_fill_backlog(struct event_base *base, int port)
|
|
|
|
{
|
|
|
|
#define BACKLOG_SIZE 256
|
2021-12-21 08:47:00 +03:00
|
|
|
struct evhttp_connection **evcons = calloc(BACKLOG_SIZE + 1, sizeof(*evcons));
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < BACKLOG_SIZE; ++i) {
|
|
|
|
struct evhttp_request *req;
|
|
|
|
|
2021-12-21 08:47:00 +03:00
|
|
|
evcons[i] = evhttp_connection_base_new(base, NULL, "127.0.0.1", port);
|
|
|
|
tt_assert(evcons[i]);
|
|
|
|
evhttp_connection_set_timeout(evcons[i], 5);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
req = evhttp_request_new(http_request_never_call, NULL);
|
|
|
|
tt_assert(req);
|
2021-12-21 08:47:00 +03:00
|
|
|
tt_int_op(evhttp_make_request(evcons[i], req, EVHTTP_REQ_GET, "/delay"), !=, -1);
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
}
|
2021-12-21 08:47:00 +03:00
|
|
|
evcons[i] = NULL;
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
|
2021-12-21 08:47:00 +03:00
|
|
|
return evcons;
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
end:
|
2021-12-21 08:47:00 +03:00
|
|
|
http_free_evcons(evcons);
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
fprintf(stderr, "Couldn't fill the backlog");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum http_cancel_test_type {
|
|
|
|
BASIC = 1,
|
|
|
|
BY_HOST = 2,
|
|
|
|
NO_NS = 4,
|
|
|
|
INACTIVE_SERVER = 8,
|
|
|
|
SERVER_TIMEOUT = 16,
|
2016-03-24 10:27:24 +03:00
|
|
|
NS_TIMEOUT = 32,
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
};
|
2016-03-24 20:26:50 +03:00
|
|
|
static struct evhttp_request *
|
|
|
|
http_cancel_test_bad_request_new(enum http_cancel_test_type type,
|
|
|
|
struct event_base *base)
|
|
|
|
{
|
2016-03-24 20:29:25 +03:00
|
|
|
#ifndef _WIN32
|
2016-03-24 20:26:50 +03:00
|
|
|
if (!(type & NO_NS) && (type & SERVER_TIMEOUT))
|
|
|
|
return evhttp_request_new(http_timed_out_request_done, base);
|
2016-03-24 20:29:25 +03:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if ((type & INACTIVE_SERVER) || (type & NO_NS))
|
2016-03-24 20:26:50 +03:00
|
|
|
return evhttp_request_new(http_failed_request_done, base);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-05-12 03:12:09 +00:00
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_cancel_test(void *arg)
|
2008-05-12 03:12:09 +00:00
|
|
|
{
|
2010-11-03 13:55:20 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2008-05-12 03:12:09 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
struct bufferevent *bufev = NULL;
|
2008-05-12 03:12:09 +00:00
|
|
|
struct timeval tv;
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
struct evdns_base *dns_base = NULL;
|
|
|
|
ev_uint16_t portnum = 0;
|
|
|
|
char address[64];
|
|
|
|
struct evhttp *inactive_http = NULL;
|
|
|
|
struct event_base *inactive_base = NULL;
|
|
|
|
struct evhttp_connection **evcons = NULL;
|
2016-06-17 16:14:02 +03:00
|
|
|
struct event_base *base_to_fill = data->base;
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
|
2016-06-17 16:07:15 +03:00
|
|
|
enum http_cancel_test_type type =
|
|
|
|
(enum http_cancel_test_type)data->setup_data;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
|
|
|
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
if (type & BY_HOST) {
|
2016-03-24 14:11:10 +03:00
|
|
|
const char *timeout = (type & NS_TIMEOUT) ? "6" : "3";
|
|
|
|
|
2020-05-21 12:46:20 +03:00
|
|
|
tt_assert(regress_dnsserver(data->base, &portnum, search_table, NULL));
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
|
|
|
|
dns_base = evdns_base_new(data->base, 0/* init name servers */);
|
|
|
|
tt_assert(dns_base);
|
|
|
|
|
|
|
|
/** XXX: Hack the port to make timeout after resolving */
|
|
|
|
if (type & NO_NS)
|
|
|
|
++portnum;
|
|
|
|
|
|
|
|
evutil_snprintf(address, sizeof(address), "127.0.0.1:%d", portnum);
|
|
|
|
evdns_base_nameserver_ip_add(dns_base, address);
|
2016-03-24 10:27:24 +03:00
|
|
|
|
|
|
|
evdns_base_set_option(dns_base, "timeout:", timeout);
|
|
|
|
evdns_base_set_option(dns_base, "initial-probe-timeout:", timeout);
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
evdns_base_set_option(dns_base, "attempts:", "1");
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 14:13:20 -04:00
|
|
|
exit_base = data->base;
|
2010-11-03 13:55:20 -04:00
|
|
|
|
2008-05-12 03:12:09 +00:00
|
|
|
test_ok = 0;
|
|
|
|
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
if (type & INACTIVE_SERVER) {
|
|
|
|
port = 0;
|
|
|
|
inactive_base = event_base_new();
|
|
|
|
inactive_http = http_setup(&port, inactive_base, 0);
|
2016-06-17 16:14:02 +03:00
|
|
|
|
|
|
|
base_to_fill = inactive_base;
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type & SERVER_TIMEOUT)
|
2021-12-21 08:47:00 +03:00
|
|
|
{
|
2016-06-17 16:14:02 +03:00
|
|
|
evcons = http_fill_backlog(base_to_fill, port);
|
2021-12-21 08:47:00 +03:00
|
|
|
tt_assert(evcons);
|
|
|
|
}
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
|
|
|
|
evcon = evhttp_connection_base_new(
|
|
|
|
data->base, dns_base,
|
|
|
|
type & BY_HOST ? "localhost" : "127.0.0.1",
|
|
|
|
port);
|
|
|
|
if (type & INACTIVE_SERVER)
|
|
|
|
evhttp_connection_set_timeout(evcon, 5);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
bufev = evhttp_connection_get_bufferevent(evcon);
|
|
|
|
/* Guarantee that we stack in connect() not after waiting EV_READ after
|
|
|
|
* write() */
|
|
|
|
if (type & SERVER_TIMEOUT)
|
|
|
|
evbuffer_add_cb(bufferevent_get_output(bufev), http_no_write, NULL);
|
|
|
|
|
2008-05-12 03:12:09 +00:00
|
|
|
/*
|
|
|
|
* At this point, we want to schedule a request to the HTTP
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_never_call, NULL);
|
2016-03-13 13:05:25 +03:00
|
|
|
evhttp_request_set_error_cb(req, http_request_error_cb_with_cancel);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2008-05-12 03:12:09 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/delay"),
|
|
|
|
!=, -1);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
Remove compat/sys/_time.h
I've gone through everything that it declared to see where it was used,
and it seems that we probably don't need it anywhere.
Here's what it declared, and why I think we're okay dropping it.
o struct timeval {}
(Used all over, and we can't really get away with declaring it ourselves;
we need the same definition the system uses. If we can't find struct
timeval, we're pretty much sunk.)
o struct timespec {}
(Used in event.c, evdns.c, kqueue.c, evport.c. Of these,
kqueue.c and event.c include sys/_time.h. event.c conditions its use on
_EVENT_HAVE_CLOCK_GETTIME, and kqueue() only works if timespec is defined.)
o TIMEVAL_TO_TIMESPEC
(Used in kqueue.c, but every place with kqueue has sys/time.h)
o struct timezone {}
(event2/util.h has a forward declaration; only evutil.c references it and
doesn't look at its contents.)
o timerclear, timerisset, timercmp, timeradd, timersub
(Everything now uses the evutil_timer* variants.)
o ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF, struct itemerval
(These are only used in test/regress.c, which does not include _time.h)
o CLOCK_REALTIME
(Only used in evdns.c, which does not include _time.h)
o TIMESPEC_TO_TIMEVAL
o DST_*
o timespecclear, timespecisset, timespeccmp, timespecadd, timespecsub
o struct clockinfo {}
o CLOCK_VIRTUAL, CLOCK_PROF
o TIMER_RELTIME, TIMER_ABSTIME
(unused)
svn:r1494
2009-11-03 19:54:56 +00:00
|
|
|
evutil_timerclear(&tv);
|
2008-05-12 03:12:09 +00:00
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 100 * 1000;
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_once(data->base, -1, EV_TIMEOUT, http_do_cancel, req, &tv);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
if (type & NO_NS || type & INACTIVE_SERVER)
|
|
|
|
tt_int_op(test_ok, ==, 2); /** no servers responses */
|
|
|
|
else
|
|
|
|
tt_int_op(test_ok, ==, 3);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
|
|
|
/* try to make another request over the same connection */
|
|
|
|
test_ok = 0;
|
2009-01-27 21:10:31 +00:00
|
|
|
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
http_free_evcons(evcons);
|
|
|
|
if (type & SERVER_TIMEOUT)
|
2021-12-21 08:47:00 +03:00
|
|
|
{
|
2016-06-17 16:14:02 +03:00
|
|
|
evcons = http_fill_backlog(base_to_fill, port);
|
2021-12-21 08:47:00 +03:00
|
|
|
tt_assert(evcons);
|
|
|
|
}
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
|
2016-03-24 20:26:50 +03:00
|
|
|
req = http_cancel_test_bad_request_new(type, data->base);
|
|
|
|
if (!req)
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2008-05-12 03:12:09 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test"),
|
|
|
|
!=, -1);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
|
|
|
/* make another request: request empty reply */
|
|
|
|
test_ok = 0;
|
2009-01-27 21:10:31 +00:00
|
|
|
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
http_free_evcons(evcons);
|
|
|
|
if (type & SERVER_TIMEOUT)
|
2021-12-21 08:47:00 +03:00
|
|
|
{
|
2016-06-17 16:14:02 +03:00
|
|
|
evcons = http_fill_backlog(base_to_fill, port);
|
2021-12-21 08:47:00 +03:00
|
|
|
tt_assert(evcons);
|
|
|
|
}
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
|
2016-03-24 20:26:50 +03:00
|
|
|
req = http_cancel_test_bad_request_new(type, data->base);
|
|
|
|
if (!req)
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
req = evhttp_request_new(http_request_empty_done, data->base);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Empty", "itis");
|
2008-05-12 03:12:09 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test"),
|
|
|
|
!=, -1);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-05-12 03:12:09 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
http_free_evcons(evcons);
|
|
|
|
if (bufev)
|
|
|
|
evbuffer_remove_cb(bufferevent_get_output(bufev), http_no_write, NULL);
|
2009-01-30 17:44:13 +00:00
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
if (dns_base)
|
|
|
|
evdns_base_free(dns_base, 0);
|
|
|
|
regress_clean_dnsserver();
|
|
|
|
if (inactive_http)
|
|
|
|
evhttp_free(inactive_http);
|
|
|
|
if (inactive_base)
|
|
|
|
event_base_free(inactive_base);
|
2008-05-12 03:12:09 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 19:15:18 +03:00
|
|
|
static void
|
|
|
|
http_request_no_action_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
EVUTIL_ASSERT(exit_base);
|
|
|
|
event_base_loopexit(exit_base, NULL);
|
|
|
|
}
|
|
|
|
|
2008-05-07 01:52:24 +00:00
|
|
|
static void
|
2006-01-22 05:08:50 +00:00
|
|
|
http_request_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2008-07-02 06:08:16 +00:00
|
|
|
const char *what = arg;
|
2006-01-22 05:08:50 +00:00
|
|
|
|
2016-11-19 15:54:52 +03:00
|
|
|
if (!req) {
|
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_response_code(req) != HTTP_OK) {
|
2006-01-22 05:08:50 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req), "Content-Type") == NULL) {
|
2006-01-22 05:08:50 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_get_length(evhttp_request_get_input_buffer(req)) != strlen(what)) {
|
2006-01-22 05:08:50 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_datacmp(evhttp_request_get_input_buffer(req), what) != 0) {
|
2006-01-22 05:08:50 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_ok = 1;
|
2010-11-03 15:04:44 -04:00
|
|
|
EVUTIL_ASSERT(exit_base);
|
|
|
|
event_base_loopexit(exit_base, NULL);
|
2006-01-22 05:08:50 +00:00
|
|
|
}
|
|
|
|
|
2008-05-07 01:52:24 +00:00
|
|
|
static void
|
|
|
|
http_request_expect_error(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_response_code(req) == HTTP_OK) {
|
2008-05-07 01:52:24 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_ok = 1;
|
2010-11-03 15:04:44 -04:00
|
|
|
EVUTIL_ASSERT(arg);
|
|
|
|
event_base_loopexit(arg, NULL);
|
2008-05-07 01:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* test virtual hosts */
|
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_virtual_host_test(void *arg)
|
2008-05-07 01:52:24 +00:00
|
|
|
{
|
2010-11-03 13:55:20 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2008-05-07 01:52:24 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2008-05-10 05:58:17 +00:00
|
|
|
struct evhttp *second = NULL, *third = NULL;
|
2010-11-05 11:17:07 -07:00
|
|
|
evutil_socket_t fd;
|
|
|
|
struct bufferevent *bev;
|
|
|
|
const char *http_request;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 14:13:20 -04:00
|
|
|
exit_base = data->base;
|
2010-11-03 13:55:20 -04:00
|
|
|
|
2008-05-07 01:52:24 +00:00
|
|
|
/* virtual host */
|
|
|
|
second = evhttp_new(NULL);
|
2016-03-25 11:04:51 +03:00
|
|
|
evhttp_set_cb(second, "/funnybunny", http_basic_cb, http);
|
2008-05-10 05:58:17 +00:00
|
|
|
third = evhttp_new(NULL);
|
2016-03-25 11:04:51 +03:00
|
|
|
evhttp_set_cb(third, "/blackcoffee", http_basic_cb, http);
|
2008-05-07 01:52:24 +00:00
|
|
|
|
|
|
|
if (evhttp_add_virtual_host(http, "foo.com", second) == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't add vhost");
|
2008-05-07 01:52:24 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 05:58:17 +00:00
|
|
|
if (evhttp_add_virtual_host(http, "bar.*.foo.com", third) == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't add wildcarded vhost");
|
2008-05-10 05:58:17 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 11:17:07 -07:00
|
|
|
/* add some aliases to the vhosts */
|
|
|
|
tt_assert(evhttp_add_server_alias(second, "manolito.info") == 0);
|
|
|
|
tt_assert(evhttp_add_server_alias(third, "bonkers.org") == 0);
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2008-05-07 01:52:24 +00:00
|
|
|
|
|
|
|
/* make a request with a different host and expect an error */
|
2010-11-03 13:55:20 -04:00
|
|
|
req = evhttp_request_new(http_request_expect_error, data->base);
|
2008-05-07 01:52:24 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2008-05-07 01:52:24 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
|
|
|
"/funnybunny") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-05-07 01:52:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-05-07 01:52:24 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(test_ok == 1);
|
2008-05-07 01:52:24 +00:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
/* make a request with the right host and expect a response */
|
2008-07-02 06:08:16 +00:00
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
2008-05-07 01:52:24 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "foo.com");
|
2008-05-07 01:52:24 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
|
|
|
"/funnybunny") == -1) {
|
|
|
|
fprintf(stdout, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-05-07 01:52:24 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(test_ok == 1);
|
2008-05-07 01:52:24 +00:00
|
|
|
|
2008-05-10 05:58:17 +00:00
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
/* make a request with the right host and expect a response */
|
2008-07-02 06:08:16 +00:00
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
2008-05-10 05:58:17 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "bar.magic.foo.com");
|
2008-05-10 05:58:17 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
|
|
|
"/blackcoffee") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-05-10 05:58:17 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-05-10 05:58:17 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(test_ok == 1)
|
2008-05-10 05:58:17 +00:00
|
|
|
|
2010-11-05 11:17:07 -07:00
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
/* make a request with the right host and expect a response */
|
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
|
|
|
|
|
|
|
/* Add the information that we care about */
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "manolito.info");
|
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
|
|
|
"/funnybunny") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
tt_assert(test_ok == 1)
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
/* make a request with the right host and expect a response */
|
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
|
|
|
|
|
|
|
/* Add the Host header. This time with the optional port. */
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "bonkers.org:8000");
|
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
|
|
|
"/blackcoffee") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
tt_assert(test_ok == 1)
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
/* Now make a raw request with an absolute URI. */
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2010-11-05 11:17:07 -07:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
|
|
|
bev = bufferevent_socket_new(data->base, fd, 0);
|
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
|
|
|
http_errorcb, NULL);
|
|
|
|
|
|
|
|
/* The host in the URI should override the Host: header */
|
|
|
|
http_request =
|
|
|
|
"GET http://manolito.info/funnybunny HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
tt_int_op(test_ok, ==, 2);
|
|
|
|
|
|
|
|
bufferevent_free(bev);
|
|
|
|
evutil_closesocket(fd);
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2008-05-07 01:52:24 +00:00
|
|
|
}
|
|
|
|
|
2007-11-29 06:08:24 +00:00
|
|
|
/* test date header and content length */
|
|
|
|
|
2008-05-07 01:52:24 +00:00
|
|
|
static void
|
2007-11-29 06:08:24 +00:00
|
|
|
http_request_empty_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2016-11-19 17:11:35 +03:00
|
|
|
if (!req) {
|
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_response_code(req) != HTTP_OK) {
|
2007-11-29 06:08:24 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req), "Date") == NULL) {
|
2007-11-29 06:08:24 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req), "Content-Length") == NULL) {
|
2007-11-29 06:08:24 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (strcmp(evhttp_find_header(evhttp_request_get_input_headers(req), "Content-Length"),
|
2007-11-29 06:08:24 +00:00
|
|
|
"0")) {
|
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_get_length(evhttp_request_get_input_buffer(req)) != 0) {
|
2007-11-29 06:08:24 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_ok = 1;
|
2010-11-03 15:04:44 -04:00
|
|
|
EVUTIL_ASSERT(arg);
|
|
|
|
event_base_loopexit(arg, NULL);
|
2007-11-29 06:08:24 +00:00
|
|
|
}
|
|
|
|
|
2007-08-05 02:15:10 +00:00
|
|
|
/*
|
|
|
|
* HTTP DISPATCHER test
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
http_dispatcher_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct evbuffer *evb = evbuffer_new();
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
2007-08-05 02:15:10 +00:00
|
|
|
evbuffer_add_printf(evb, "DISPATCHER_TEST");
|
|
|
|
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is fine", evb);
|
|
|
|
|
|
|
|
evbuffer_free(evb);
|
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2007-08-05 02:15:10 +00:00
|
|
|
http_dispatcher_test_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct event_base *base = arg;
|
2007-08-05 02:15:10 +00:00
|
|
|
const char *what = "DISPATCHER_TEST";
|
|
|
|
|
2015-11-05 11:18:32 +03:00
|
|
|
if (!req) {
|
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_response_code(req) != HTTP_OK) {
|
2007-08-05 02:15:10 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req), "Content-Type") == NULL) {
|
2007-08-05 02:15:10 +00:00
|
|
|
fprintf(stderr, "FAILED (content type)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_get_length(evhttp_request_get_input_buffer(req)) != strlen(what)) {
|
2010-10-05 14:29:48 -04:00
|
|
|
fprintf(stderr, "FAILED (length %lu vs %lu)\n",
|
2010-11-03 15:14:29 -04:00
|
|
|
(unsigned long)evbuffer_get_length(evhttp_request_get_input_buffer(req)), (unsigned long)strlen(what));
|
2007-08-05 02:15:10 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_datacmp(evhttp_request_get_input_buffer(req), what) != 0) {
|
2007-08-05 02:15:10 +00:00
|
|
|
fprintf(stderr, "FAILED (data)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_ok = 1;
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(base, NULL);
|
2007-08-05 02:15:10 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2010-11-03 14:31:23 -04:00
|
|
|
http_dispatcher_test(void *arg)
|
2007-08-05 02:15:10 +00:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2007-08-05 02:15:10 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2007-08-05 02:15:10 +00:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2007-08-05 02:15:10 +00:00
|
|
|
|
2007-09-07 02:49:46 +00:00
|
|
|
/* also bind to local host */
|
|
|
|
evhttp_connection_set_local_address(evcon, "127.0.0.1");
|
|
|
|
|
2007-08-05 02:15:10 +00:00
|
|
|
/*
|
|
|
|
* At this point, we want to schedule an HTTP GET request
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
req = evhttp_request_new(http_dispatcher_test_done, data->base);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(req);
|
2007-08-05 02:15:10 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2007-08-05 02:15:10 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/?arg=val") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2007-08-05 02:15:10 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2007-08-05 02:15:10 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2007-08-05 02:15:10 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 11:31:00 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
/* test unix socket */
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
|
|
|
/* Should this be part of the libevent library itself? */
|
|
|
|
static int evhttp_bind_unixsocket(struct evhttp *httpd, const char *path)
|
|
|
|
{
|
|
|
|
struct sockaddr_un local;
|
|
|
|
struct stat st;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
local.sun_family = AF_UNIX;
|
|
|
|
strcpy(local.sun_path, path);
|
|
|
|
|
|
|
|
/* if the file exists and it is a socket, remove it. Someone
|
|
|
|
could create a symlink and get us to remove random files */
|
|
|
|
if (stat(path, &st) == 0 && S_ISSOCK(st.st_mode))
|
|
|
|
unlink(path);
|
|
|
|
|
2021-09-17 01:39:46 -04:00
|
|
|
fd = evutil_socket_(AF_UNIX,
|
|
|
|
EVUTIL_SOCK_CLOEXEC | EVUTIL_SOCK_NONBLOCK | SOCK_STREAM, 0);
|
2016-01-31 11:31:00 +00:00
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (bind(fd, (struct sockaddr*)&local, sizeof(local))) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fchmod(fd, 0777) does nothing */
|
|
|
|
if (chmod(path, 0777)) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listen(fd, 128)) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (evhttp_accept_socket(httpd, fd)) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void http_unix_socket_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
2021-09-17 04:47:34 -04:00
|
|
|
struct evhttp_uri *uri = NULL;
|
2016-01-31 11:31:00 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req;
|
2021-09-19 11:07:55 +03:00
|
|
|
struct evhttp *myhttp;
|
|
|
|
char tmp_sock_path[512];
|
|
|
|
char uri_loc[1024];
|
2016-01-31 11:31:00 +00:00
|
|
|
|
2021-09-19 11:07:55 +03:00
|
|
|
// Avoid overlap with parallel runs
|
|
|
|
evutil_snprintf(tmp_sock_path, sizeof(tmp_sock_path), "/tmp/eventtmp.%i.sock", getpid());
|
|
|
|
evutil_snprintf(uri_loc, sizeof(uri_loc), "http://unix:%s:/?arg=val", tmp_sock_path);
|
2016-01-31 11:31:00 +00:00
|
|
|
|
2021-09-19 11:07:55 +03:00
|
|
|
myhttp = evhttp_new(data->base);
|
|
|
|
tt_assert(!evhttp_bind_unixsocket(myhttp, tmp_sock_path));
|
2016-01-31 11:31:00 +00:00
|
|
|
|
|
|
|
evhttp_set_cb(myhttp, "/", http_dispatcher_cb, data->base);
|
|
|
|
|
2021-09-19 11:07:55 +03:00
|
|
|
uri = evhttp_uri_parse_with_flags(uri_loc, EVHTTP_URI_UNIX_SOCKET);
|
2016-01-31 11:31:00 +00:00
|
|
|
tt_assert(uri);
|
|
|
|
|
|
|
|
evcon = evhttp_connection_base_bufferevent_unix_new(data->base, NULL, evhttp_uri_get_unixsocket(uri));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we want to schedule an HTTP GET request
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
req = evhttp_request_new(http_dispatcher_test_done, data->base);
|
|
|
|
tt_assert(req);
|
|
|
|
|
|
|
|
/* Add the information that we care about */
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/?arg=val") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (myhttp)
|
|
|
|
evhttp_free(myhttp);
|
|
|
|
if (uri)
|
|
|
|
evhttp_uri_free(uri);
|
2021-09-19 11:07:55 +03:00
|
|
|
|
|
|
|
/* Does mkstemp() succeed? */
|
|
|
|
if (!strstr(tmp_sock_path, "XXXXXX"))
|
|
|
|
unlink(tmp_sock_path);
|
2016-01-31 11:31:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-02-27 02:27:37 +00:00
|
|
|
/*
|
|
|
|
* HTTP POST test.
|
|
|
|
*/
|
|
|
|
|
2006-07-17 00:33:57 +00:00
|
|
|
void http_postrequest_done(struct evhttp_request *, void *);
|
|
|
|
|
|
|
|
#define POST_DATA "Okay. Not really printf"
|
2006-02-27 02:27:37 +00:00
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_post_test(void *arg)
|
2006-02-27 02:27:37 +00:00
|
|
|
{
|
2010-11-03 13:55:20 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2006-02-27 02:27:37 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
2006-07-17 00:33:57 +00:00
|
|
|
struct evhttp_request *req = NULL;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2006-02-27 02:27:37 +00:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2006-02-27 02:27:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we want to schedule an HTTP POST request
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
req = evhttp_request_new(http_postrequest_done, data->base);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(req);
|
2006-02-27 02:27:37 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
evbuffer_add_printf(evhttp_request_get_output_buffer(req), POST_DATA);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2006-02-27 02:27:37 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/postit") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2006-02-27 02:27:37 +00:00
|
|
|
}
|
2006-07-17 00:33:57 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2006-07-17 00:33:57 +00:00
|
|
|
|
2010-11-29 18:25:04 -08:00
|
|
|
tt_int_op(test_ok, ==, 1);
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_postrequest_done, data->base);
|
|
|
|
tt_assert(req);
|
|
|
|
|
|
|
|
/* Now try with 100-continue. */
|
|
|
|
|
|
|
|
/* Add the information that we care about */
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Expect", "100-continue");
|
|
|
|
evbuffer_add_printf(evhttp_request_get_output_buffer(req), POST_DATA);
|
|
|
|
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/postit") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
tt_int_op(test_ok, ==, 1);
|
|
|
|
|
2006-07-17 00:33:57 +00:00
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
evhttp_free(http);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
;
|
2006-02-27 02:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
http_post_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2007-07-30 23:54:25 +00:00
|
|
|
struct evbuffer *evb;
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
2006-02-27 02:27:37 +00:00
|
|
|
|
|
|
|
/* Yes, we are expecting a post request */
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_command(req) != EVHTTP_REQ_POST) {
|
2006-08-13 00:03:35 +00:00
|
|
|
fprintf(stdout, "FAILED (post type)\n");
|
2006-02-27 02:27:37 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_get_length(evhttp_request_get_input_buffer(req)) != strlen(POST_DATA)) {
|
2010-10-05 14:29:48 -04:00
|
|
|
fprintf(stdout, "FAILED (length: %lu vs %lu)\n",
|
2010-11-03 15:14:29 -04:00
|
|
|
(unsigned long) evbuffer_get_length(evhttp_request_get_input_buffer(req)), (unsigned long) strlen(POST_DATA));
|
2006-02-27 02:27:37 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_datacmp(evhttp_request_get_input_buffer(req), POST_DATA) != 0) {
|
2006-08-13 00:03:35 +00:00
|
|
|
fprintf(stdout, "FAILED (data)\n");
|
2010-11-03 15:14:29 -04:00
|
|
|
fprintf(stdout, "Got :%s\n", evbuffer_pullup(evhttp_request_get_input_buffer(req),-1));
|
2006-08-13 00:03:35 +00:00
|
|
|
fprintf(stdout, "Want:%s\n", POST_DATA);
|
2006-02-27 02:27:37 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2007-07-30 23:54:25 +00:00
|
|
|
evb = evbuffer_new();
|
2008-07-02 06:08:16 +00:00
|
|
|
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
2006-02-27 02:27:37 +00:00
|
|
|
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is fine", evb);
|
|
|
|
|
|
|
|
evbuffer_free(evb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
http_postrequest_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2008-07-02 06:08:16 +00:00
|
|
|
const char *what = BASIC_REQUEST_BODY;
|
2010-11-03 13:55:20 -04:00
|
|
|
struct event_base *base = arg;
|
2006-02-27 02:27:37 +00:00
|
|
|
|
2007-08-06 20:53:33 +00:00
|
|
|
if (req == NULL) {
|
|
|
|
fprintf(stderr, "FAILED (timeout)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_response_code(req) != HTTP_OK) {
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2006-08-13 00:03:35 +00:00
|
|
|
fprintf(stderr, "FAILED (response code)\n");
|
2006-02-27 02:27:37 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req), "Content-Type") == NULL) {
|
2006-08-13 00:03:35 +00:00
|
|
|
fprintf(stderr, "FAILED (content type)\n");
|
2006-02-27 02:27:37 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_get_length(evhttp_request_get_input_buffer(req)) != strlen(what)) {
|
2010-10-05 14:29:48 -04:00
|
|
|
fprintf(stderr, "FAILED (length %lu vs %lu)\n",
|
2010-11-03 15:14:29 -04:00
|
|
|
(unsigned long)evbuffer_get_length(evhttp_request_get_input_buffer(req)), (unsigned long)strlen(what));
|
2006-02-27 02:27:37 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_datacmp(evhttp_request_get_input_buffer(req), what) != 0) {
|
2006-08-13 00:03:35 +00:00
|
|
|
fprintf(stderr, "FAILED (data)\n");
|
2006-02-27 02:27:37 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_ok = 1;
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_loopexit(base, NULL);
|
2006-02-27 02:27:37 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 06:20:48 +00:00
|
|
|
/*
|
|
|
|
* HTTP PUT test, basically just like POST, but ...
|
|
|
|
*/
|
|
|
|
|
|
|
|
void http_putrequest_done(struct evhttp_request *, void *);
|
|
|
|
|
|
|
|
#define PUT_DATA "Hi, I'm some PUT data"
|
|
|
|
|
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_put_test(void *arg)
|
2008-02-27 06:20:48 +00:00
|
|
|
{
|
2010-11-03 13:55:20 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2008-02-27 06:20:48 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2008-02-27 06:20:48 +00:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2008-02-27 06:20:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Schedule the HTTP PUT request
|
|
|
|
*/
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
req = evhttp_request_new(http_putrequest_done, data->base);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(req);
|
2008-02-27 06:20:48 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "someotherhost");
|
|
|
|
evbuffer_add_printf(evhttp_request_get_output_buffer(req), PUT_DATA);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-02-27 06:20:48 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_PUT, "/putit") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-02-27 06:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-02-27 06:20:48 +00:00
|
|
|
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
evhttp_free(http);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(test_ok, ==, 1);
|
|
|
|
end:
|
|
|
|
;
|
2008-02-27 06:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
http_put_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *evb;
|
2018-10-28 19:27:05 +03:00
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
2008-02-27 06:20:48 +00:00
|
|
|
|
|
|
|
/* Expecting a PUT request */
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_command(req) != EVHTTP_REQ_PUT) {
|
2008-02-27 06:20:48 +00:00
|
|
|
fprintf(stdout, "FAILED (put type)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_get_length(evhttp_request_get_input_buffer(req)) != strlen(PUT_DATA)) {
|
2010-10-05 14:29:48 -04:00
|
|
|
fprintf(stdout, "FAILED (length: %lu vs %lu)\n",
|
2010-11-03 15:14:29 -04:00
|
|
|
(unsigned long)evbuffer_get_length(evhttp_request_get_input_buffer(req)), (unsigned long)strlen(PUT_DATA));
|
2009-07-14 18:50:06 +00:00
|
|
|
exit(1);
|
2008-02-27 06:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_datacmp(evhttp_request_get_input_buffer(req), PUT_DATA) != 0) {
|
2008-02-27 06:20:48 +00:00
|
|
|
fprintf(stdout, "FAILED (data)\n");
|
2010-11-03 15:14:29 -04:00
|
|
|
fprintf(stdout, "Got :%s\n", evbuffer_pullup(evhttp_request_get_input_buffer(req),-1));
|
2008-02-27 06:20:48 +00:00
|
|
|
fprintf(stdout, "Want:%s\n", PUT_DATA);
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-02-27 06:20:48 +00:00
|
|
|
evb = evbuffer_new();
|
|
|
|
evbuffer_add_printf(evb, "That ain't funny");
|
|
|
|
|
|
|
|
evhttp_send_reply(req, HTTP_OK, "Everything is great", evb);
|
|
|
|
|
|
|
|
evbuffer_free(evb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
http_putrequest_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2010-11-03 13:55:20 -04:00
|
|
|
struct event_base *base = arg;
|
2008-02-27 06:20:48 +00:00
|
|
|
const char *what = "That ain't funny";
|
|
|
|
|
|
|
|
if (req == NULL) {
|
|
|
|
fprintf(stderr, "FAILED (timeout)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_response_code(req) != HTTP_OK) {
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-02-27 06:20:48 +00:00
|
|
|
fprintf(stderr, "FAILED (response code)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req), "Content-Type") == NULL) {
|
2008-02-27 06:20:48 +00:00
|
|
|
fprintf(stderr, "FAILED (content type)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_get_length(evhttp_request_get_input_buffer(req)) != strlen(what)) {
|
2010-10-05 14:29:48 -04:00
|
|
|
fprintf(stderr, "FAILED (length %lu vs %lu)\n",
|
2010-11-03 15:14:29 -04:00
|
|
|
(unsigned long)evbuffer_get_length(evhttp_request_get_input_buffer(req)), (unsigned long)strlen(what));
|
2008-02-27 06:20:48 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-10-21 12:48:13 -04:00
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_datacmp(evhttp_request_get_input_buffer(req), what) != 0) {
|
2008-02-27 06:20:48 +00:00
|
|
|
fprintf(stderr, "FAILED (data)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_ok = 1;
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_loopexit(base, NULL);
|
2008-02-27 06:20:48 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2006-11-17 06:06:17 +00:00
|
|
|
http_failure_readcb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
|
|
|
const char *what = "400 Bad Request";
|
2010-10-21 12:48:13 -04:00
|
|
|
if (evbuffer_contains(bufferevent_get_input(bev), what)) {
|
2006-11-17 06:06:17 +00:00
|
|
|
test_ok = 2;
|
2006-11-18 08:51:12 +00:00
|
|
|
bufferevent_disable(bev, EV_READ);
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_loopexit(arg, NULL);
|
2006-11-17 06:06:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing that the HTTP server can deal with a malformed request.
|
|
|
|
*/
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_failure_test(void *arg)
|
2006-11-17 06:06:17 +00:00
|
|
|
{
|
2010-11-03 13:55:20 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2006-11-17 06:06:17 +00:00
|
|
|
struct bufferevent *bev;
|
2019-01-29 21:12:33 +03:00
|
|
|
evutil_socket_t fd = EVUTIL_INVALID_SOCKET;
|
2007-11-26 19:18:49 +00:00
|
|
|
const char *http_request;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2006-11-17 06:06:17 +00:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2006-11-17 06:06:17 +00:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2010-11-03 13:55:20 -04:00
|
|
|
bev = bufferevent_socket_new(data->base, fd, 0);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev, http_failure_readcb, http_writecb,
|
2010-11-03 13:55:20 -04:00
|
|
|
http_errorcb, data->base);
|
2006-11-17 06:06:17 +00:00
|
|
|
|
|
|
|
http_request = "illegal request\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2006-11-17 06:06:17 +00:00
|
|
|
|
|
|
|
bufferevent_free(bev);
|
|
|
|
|
|
|
|
evhttp_free(http);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(test_ok, ==, 2);
|
|
|
|
end:
|
2014-01-08 13:02:37 -05:00
|
|
|
if (fd >= 0)
|
|
|
|
evutil_closesocket(fd);
|
2006-11-17 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 06:32:20 +00:00
|
|
|
static void
|
|
|
|
close_detect_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2008-12-19 22:42:51 +00:00
|
|
|
struct timeval tv;
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(req);
|
2010-11-03 15:14:29 -04:00
|
|
|
tt_assert(evhttp_request_get_response_code(req) == HTTP_OK);
|
2006-11-23 06:32:20 +00:00
|
|
|
|
|
|
|
test_ok = 1;
|
2008-12-19 22:42:51 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
Remove compat/sys/_time.h
I've gone through everything that it declared to see where it was used,
and it seems that we probably don't need it anywhere.
Here's what it declared, and why I think we're okay dropping it.
o struct timeval {}
(Used all over, and we can't really get away with declaring it ourselves;
we need the same definition the system uses. If we can't find struct
timeval, we're pretty much sunk.)
o struct timespec {}
(Used in event.c, evdns.c, kqueue.c, evport.c. Of these,
kqueue.c and event.c include sys/_time.h. event.c conditions its use on
_EVENT_HAVE_CLOCK_GETTIME, and kqueue() only works if timespec is defined.)
o TIMEVAL_TO_TIMESPEC
(Used in kqueue.c, but every place with kqueue has sys/time.h)
o struct timezone {}
(event2/util.h has a forward declaration; only evutil.c references it and
doesn't look at its contents.)
o timerclear, timerisset, timercmp, timeradd, timersub
(Everything now uses the evutil_timer* variants.)
o ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF, struct itemerval
(These are only used in test/regress.c, which does not include _time.h)
o CLOCK_REALTIME
(Only used in evdns.c, which does not include _time.h)
o TIMESPEC_TO_TIMEVAL
o DST_*
o timespecclear, timespecisset, timespeccmp, timespecadd, timespecsub
o struct clockinfo {}
o CLOCK_VIRTUAL, CLOCK_PROF
o TIMER_RELTIME, TIMER_ABSTIME
(unused)
svn:r1494
2009-11-03 19:54:56 +00:00
|
|
|
evutil_timerclear(&tv);
|
2012-01-24 14:33:10 -05:00
|
|
|
tv.tv_usec = 150000;
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_loopexit(arg, &tv);
|
2006-11-23 06:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-05 12:47:46 -05:00
|
|
|
close_detect_launch(evutil_socket_t fd, short what, void *arg)
|
2006-11-23 06:32:20 +00:00
|
|
|
{
|
|
|
|
struct evhttp_connection *evcon = arg;
|
2010-11-03 13:55:20 -04:00
|
|
|
struct event_base *base = evhttp_connection_get_base(evcon);
|
2006-11-23 06:32:20 +00:00
|
|
|
struct evhttp_request *req;
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
req = evhttp_request_new(close_detect_done, base);
|
2006-11-23 06:32:20 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2006-11-23 06:32:20 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_fail_msg("Couldn't make request");
|
2006-11-23 06:32:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
close_detect_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evhttp_connection *evcon = arg;
|
2010-11-03 13:55:20 -04:00
|
|
|
struct event_base *base = evhttp_connection_get_base(evcon);
|
2006-11-23 06:32:20 +00:00
|
|
|
struct timeval tv;
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (req != NULL && evhttp_request_get_response_code(req) != HTTP_OK) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Failed");
|
2006-11-23 06:32:20 +00:00
|
|
|
}
|
|
|
|
|
Remove compat/sys/_time.h
I've gone through everything that it declared to see where it was used,
and it seems that we probably don't need it anywhere.
Here's what it declared, and why I think we're okay dropping it.
o struct timeval {}
(Used all over, and we can't really get away with declaring it ourselves;
we need the same definition the system uses. If we can't find struct
timeval, we're pretty much sunk.)
o struct timespec {}
(Used in event.c, evdns.c, kqueue.c, evport.c. Of these,
kqueue.c and event.c include sys/_time.h. event.c conditions its use on
_EVENT_HAVE_CLOCK_GETTIME, and kqueue() only works if timespec is defined.)
o TIMEVAL_TO_TIMESPEC
(Used in kqueue.c, but every place with kqueue has sys/time.h)
o struct timezone {}
(event2/util.h has a forward declaration; only evutil.c references it and
doesn't look at its contents.)
o timerclear, timerisset, timercmp, timeradd, timersub
(Everything now uses the evutil_timer* variants.)
o ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF, struct itemerval
(These are only used in test/regress.c, which does not include _time.h)
o CLOCK_REALTIME
(Only used in evdns.c, which does not include _time.h)
o TIMESPEC_TO_TIMEVAL
o DST_*
o timespecclear, timespecisset, timespeccmp, timespecadd, timespecsub
o struct clockinfo {}
o CLOCK_VIRTUAL, CLOCK_PROF
o TIMER_RELTIME, TIMER_ABSTIME
(unused)
svn:r1494
2009-11-03 19:54:56 +00:00
|
|
|
evutil_timerclear(&tv);
|
2012-01-24 14:33:10 -05:00
|
|
|
tv.tv_sec = 0; /* longer than the http time out */
|
|
|
|
tv.tv_usec = 600000; /* longer than the http time out */
|
2006-11-23 06:32:20 +00:00
|
|
|
|
2012-01-24 14:33:10 -05:00
|
|
|
/* launch a new request on the persistent connection in .3 seconds */
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_once(base, -1, EV_TIMEOUT, close_detect_launch, evcon, &tv);
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
;
|
2006-11-23 06:32:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2012-02-29 15:07:32 -05:00
|
|
|
http_close_detection_(struct basic_test_data *data, int with_delay)
|
2006-11-23 06:32:20 +00:00
|
|
|
{
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2006-11-23 06:32:20 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2012-01-24 14:33:10 -05:00
|
|
|
const struct timeval sec_tenth = { 0, 100000 };
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2006-11-23 06:32:20 +00:00
|
|
|
test_ok = 0;
|
|
|
|
|
2012-01-24 14:33:10 -05:00
|
|
|
/* .1 second timeout */
|
|
|
|
evhttp_set_timeout_tv(http, &sec_tenth);
|
2006-11-23 06:32:20 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL,
|
|
|
|
"127.0.0.1", port);
|
2014-01-08 11:51:22 -05:00
|
|
|
tt_assert(evcon);
|
2012-01-24 14:33:10 -05:00
|
|
|
evhttp_connection_set_timeout_tv(evcon, &sec_tenth);
|
|
|
|
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2008-12-19 22:42:51 +00:00
|
|
|
delayed_client = evcon;
|
|
|
|
|
2006-11-23 06:32:20 +00:00
|
|
|
/*
|
|
|
|
* At this point, we want to schedule a request to the HTTP
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
req = evhttp_request_new(close_detect_cb, evcon);
|
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2006-11-23 06:32:20 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
2008-12-19 22:42:51 +00:00
|
|
|
if (evhttp_make_request(evcon,
|
|
|
|
req, EVHTTP_REQ_GET, with_delay ? "/largedelay" : "/test") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("couldn't make request");
|
2006-11-23 06:32:20 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2006-11-23 06:32:20 +00:00
|
|
|
|
2008-12-19 22:42:51 +00:00
|
|
|
/* at this point, the http server should have no connection */
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(TAILQ_FIRST(&http->connections) == NULL);
|
2008-12-19 22:42:51 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_close_detection_test(void *arg)
|
2009-01-30 17:44:13 +00:00
|
|
|
{
|
2012-02-29 15:07:32 -05:00
|
|
|
http_close_detection_(arg, 0);
|
2009-01-30 17:44:13 +00:00
|
|
|
}
|
|
|
|
static void
|
2010-11-03 13:55:20 -04:00
|
|
|
http_close_detection_delay_test(void *arg)
|
2009-01-30 17:44:13 +00:00
|
|
|
{
|
2012-02-29 15:07:32 -05:00
|
|
|
http_close_detection_(arg, 1);
|
2006-11-23 06:32:20 +00:00
|
|
|
}
|
2006-02-27 02:27:37 +00:00
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2010-11-03 14:31:23 -04:00
|
|
|
http_highport_test(void *arg)
|
2007-01-18 06:28:42 +00:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2007-01-18 06:28:42 +00:00
|
|
|
int i = -1;
|
|
|
|
struct evhttp *myhttp = NULL;
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2007-01-18 06:28:42 +00:00
|
|
|
/* Try a few different ports */
|
|
|
|
for (i = 0; i < 50; ++i) {
|
2010-11-03 14:31:23 -04:00
|
|
|
myhttp = evhttp_new(data->base);
|
|
|
|
if (evhttp_bind_socket(myhttp, "127.0.0.1", 65535 - i) == 0) {
|
2009-01-30 17:44:13 +00:00
|
|
|
test_ok = 1;
|
2007-01-18 06:28:42 +00:00
|
|
|
evhttp_free(myhttp);
|
|
|
|
return;
|
|
|
|
}
|
2010-11-03 14:31:23 -04:00
|
|
|
evhttp_free(myhttp);
|
2007-01-18 06:28:42 +00:00
|
|
|
}
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_fail_msg("Couldn't get a high port");
|
2007-01-18 06:28:42 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2009-01-30 17:44:13 +00:00
|
|
|
http_bad_header_test(void *ptr)
|
2007-08-06 21:00:49 +00:00
|
|
|
{
|
|
|
|
struct evkeyvalq headers;
|
|
|
|
|
|
|
|
TAILQ_INIT(&headers);
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_want(evhttp_add_header(&headers, "One", "Two") == 0);
|
2009-04-10 05:43:45 +00:00
|
|
|
tt_want(evhttp_add_header(&headers, "One", "Two\r\n Three") == 0);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_want(evhttp_add_header(&headers, "One\r", "Two") == -1);
|
|
|
|
tt_want(evhttp_add_header(&headers, "One\n", "Two") == -1);
|
|
|
|
tt_want(evhttp_add_header(&headers, "One", "Two\r") == -1);
|
|
|
|
tt_want(evhttp_add_header(&headers, "One", "Two\n") == -1);
|
2007-08-06 21:00:49 +00:00
|
|
|
|
2007-09-09 01:46:35 +00:00
|
|
|
evhttp_clear_headers(&headers);
|
2007-08-06 21:00:49 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 05:43:45 +00:00
|
|
|
static int validate_header(
|
|
|
|
const struct evkeyvalq* headers,
|
2009-07-17 18:38:38 +00:00
|
|
|
const char *key, const char *value)
|
2009-04-10 05:43:45 +00:00
|
|
|
{
|
|
|
|
const char *real_val = evhttp_find_header(headers, key);
|
|
|
|
tt_assert(real_val != NULL);
|
|
|
|
tt_want(strcmp(real_val, value) == 0);
|
|
|
|
end:
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_parse_query_test(void *ptr)
|
|
|
|
{
|
|
|
|
struct evkeyvalq headers;
|
2010-10-06 11:48:52 -04:00
|
|
|
int r;
|
2009-04-10 05:43:45 +00:00
|
|
|
|
|
|
|
TAILQ_INIT(&headers);
|
2009-07-17 18:38:38 +00:00
|
|
|
|
2010-10-06 11:48:52 -04:00
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=test", &headers);
|
2009-04-10 05:43:45 +00:00
|
|
|
tt_want(validate_header(&headers, "q", "test") == 0);
|
2010-10-06 11:48:52 -04:00
|
|
|
tt_int_op(r, ==, 0);
|
2009-04-10 05:43:45 +00:00
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
2010-10-06 11:48:52 -04:00
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=test&foo=bar", &headers);
|
2009-04-10 05:43:45 +00:00
|
|
|
tt_want(validate_header(&headers, "q", "test") == 0);
|
|
|
|
tt_want(validate_header(&headers, "foo", "bar") == 0);
|
2010-10-06 11:48:52 -04:00
|
|
|
tt_int_op(r, ==, 0);
|
2009-04-10 05:43:45 +00:00
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
2010-10-06 11:48:52 -04:00
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=test+foo", &headers);
|
2009-04-10 05:43:45 +00:00
|
|
|
tt_want(validate_header(&headers, "q", "test foo") == 0);
|
2010-10-06 11:48:52 -04:00
|
|
|
tt_int_op(r, ==, 0);
|
2009-04-10 05:43:45 +00:00
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
2010-10-06 11:48:52 -04:00
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=test%0Afoo", &headers);
|
2009-04-10 05:43:45 +00:00
|
|
|
tt_want(validate_header(&headers, "q", "test\nfoo") == 0);
|
2010-10-06 11:48:52 -04:00
|
|
|
tt_int_op(r, ==, 0);
|
2009-04-10 05:43:45 +00:00
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
2010-10-06 11:48:52 -04:00
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=test%0Dfoo", &headers);
|
2009-04-10 05:43:45 +00:00
|
|
|
tt_want(validate_header(&headers, "q", "test\rfoo") == 0);
|
2010-10-06 11:48:52 -04:00
|
|
|
tt_int_op(r, ==, 0);
|
2009-04-10 05:43:45 +00:00
|
|
|
evhttp_clear_headers(&headers);
|
2010-10-06 11:48:52 -04:00
|
|
|
|
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=test&&q2", &headers);
|
|
|
|
tt_int_op(r, ==, -1);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=test+this", &headers);
|
|
|
|
tt_want(validate_header(&headers, "q", "test this") == 0);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=test&q2=foo", &headers);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
tt_want(validate_header(&headers, "q", "test") == 0);
|
|
|
|
tt_want(validate_header(&headers, "q2", "foo") == 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query("http://www.test.com/?q&q2=foo", &headers);
|
|
|
|
tt_int_op(r, ==, -1);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=foo&q2", &headers);
|
|
|
|
tt_int_op(r, ==, -1);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=foo&q2&q3=x", &headers);
|
|
|
|
tt_int_op(r, ==, -1);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query("http://www.test.com/?q=&q2=&q3=", &headers);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
tt_want(validate_header(&headers, "q", "") == 0);
|
|
|
|
tt_want(validate_header(&headers, "q2", "") == 0);
|
|
|
|
tt_want(validate_header(&headers, "q3", "") == 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
2018-10-27 17:36:09 +03:00
|
|
|
end:
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
http_parse_query_str_test(void *ptr)
|
|
|
|
{
|
|
|
|
struct evkeyvalq headers;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
TAILQ_INIT(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query_str("http://www.test.com/?q=test", &headers);
|
|
|
|
tt_assert(evhttp_find_header(&headers, "q") == NULL);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query_str("q=test", &headers);
|
|
|
|
tt_want(validate_header(&headers, "q", "test") == 0);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
2018-10-27 17:21:35 +03:00
|
|
|
end:
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
http_parse_query_str_flags_test(void *ptr)
|
|
|
|
{
|
|
|
|
struct evkeyvalq headers;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
TAILQ_INIT(&headers);
|
|
|
|
|
|
|
|
/** ~EVHTTP_URI_QUERY_LAST_VAL */
|
|
|
|
r = evhttp_parse_query_str_flags("q=test&q=test2", &headers, 0);
|
|
|
|
tt_want(validate_header(&headers, "q", "test") == 0);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
/** EVHTTP_URI_QUERY_LAST_VAL */
|
|
|
|
r = evhttp_parse_query_str_flags("q=test&q=test2", &headers, EVHTTP_URI_QUERY_LAST_VAL);
|
|
|
|
tt_want(validate_header(&headers, "q", "test2") == 0);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
/** ~EVHTTP_URI_QUERY_NONCONFORMANT */
|
|
|
|
r = evhttp_parse_query_str_flags("q=test&q2", &headers, 0);
|
|
|
|
tt_int_op(r, ==, -1);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query_str_flags("q=test&&q2=test2", &headers, 0);
|
|
|
|
tt_int_op(r, ==, -1);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query_str_flags("q=test&=1&q2=test2", &headers, 0);
|
|
|
|
tt_int_op(r, ==, -1);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
/** EVHTTP_URI_QUERY_NONCONFORMANT */
|
|
|
|
r = evhttp_parse_query_str_flags("q=test&q2", &headers, EVHTTP_URI_QUERY_NONCONFORMANT);
|
|
|
|
tt_want(validate_header(&headers, "q", "test") == 0);
|
|
|
|
tt_want(validate_header(&headers, "q2", "") == 0);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query_str_flags("q=test&&q2=test2", &headers, EVHTTP_URI_QUERY_NONCONFORMANT);
|
|
|
|
tt_want(validate_header(&headers, "q", "test") == 0);
|
|
|
|
tt_want(validate_header(&headers, "q2", "test2") == 0);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
r = evhttp_parse_query_str_flags("q=test&=1&q2=test2", &headers, EVHTTP_URI_QUERY_NONCONFORMANT);
|
|
|
|
tt_want(validate_header(&headers, "q", "test") == 0);
|
|
|
|
tt_want(validate_header(&headers, "q2", "test2") == 0);
|
|
|
|
tt_int_op(r, ==, 0);
|
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
|
|
|
|
|
2010-10-06 11:48:52 -04:00
|
|
|
end:
|
2009-04-10 05:43:45 +00:00
|
|
|
evhttp_clear_headers(&headers);
|
|
|
|
}
|
|
|
|
|
2010-08-08 16:46:39 +04:00
|
|
|
static void
|
2021-08-10 23:14:01 +03:00
|
|
|
http_parse_uri_test(void *arg)
|
2010-08-08 16:46:39 +04:00
|
|
|
{
|
2016-01-31 11:31:00 +00:00
|
|
|
int nonconform = 0, unixsock = 0;
|
|
|
|
int parse_flags = 0;
|
2010-08-08 16:46:39 +04:00
|
|
|
struct evhttp_uri *uri = NULL;
|
|
|
|
char url_tmp[4096];
|
2021-08-10 23:14:01 +03:00
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
const char *setup_data = data ? data->setup_data : NULL;
|
2020-10-27 01:40:34 +03:00
|
|
|
#define URI_PARSE_FLAGS(uri, flags) \
|
|
|
|
evhttp_uri_parse_with_flags((uri), flags)
|
2011-02-13 00:41:22 -05:00
|
|
|
#define URI_PARSE(uri) \
|
|
|
|
evhttp_uri_parse_with_flags((uri), parse_flags)
|
2010-08-08 16:46:39 +04:00
|
|
|
|
|
|
|
#define TT_URI(want) do { \
|
|
|
|
char *ret = evhttp_uri_join(uri, url_tmp, sizeof(url_tmp)); \
|
|
|
|
tt_want(ret != NULL); \
|
|
|
|
tt_want(ret == url_tmp); \
|
2010-10-19 12:35:50 -04:00
|
|
|
if (strcmp(ret,want) != 0) \
|
|
|
|
TT_FAIL(("\"%s\" != \"%s\"",ret,want)); \
|
2010-08-08 16:46:39 +04:00
|
|
|
} while(0)
|
|
|
|
|
2021-08-10 23:14:01 +03:00
|
|
|
if (setup_data) {
|
|
|
|
if (strstr(setup_data, "nc") != NULL) {
|
2016-01-31 11:31:00 +00:00
|
|
|
nonconform = 1;
|
|
|
|
parse_flags |= EVHTTP_URI_NONCONFORMANT;
|
|
|
|
}
|
2021-08-10 23:14:01 +03:00
|
|
|
if (strstr(setup_data, "un") != NULL) {
|
2016-01-31 11:31:00 +00:00
|
|
|
unixsock = 1;
|
|
|
|
parse_flags |= EVHTTP_URI_UNIX_SOCKET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 12:35:50 -04:00
|
|
|
tt_want(evhttp_uri_join(NULL, 0, 0) == NULL);
|
|
|
|
tt_want(evhttp_uri_join(NULL, url_tmp, 0) == NULL);
|
|
|
|
tt_want(evhttp_uri_join(NULL, url_tmp, sizeof(url_tmp)) == NULL);
|
|
|
|
|
|
|
|
/* bad URIs: parsing */
|
|
|
|
#define BAD(s) do { \
|
2011-02-13 00:41:22 -05:00
|
|
|
if (URI_PARSE(s) != NULL) \
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_FAIL(("Expected error parsing \"%s\"",s)); \
|
|
|
|
} while(0)
|
2011-02-13 00:41:22 -05:00
|
|
|
/* Nonconformant URIs we can parse: parsing */
|
|
|
|
#define NCF(s) do { \
|
|
|
|
uri = URI_PARSE(s); \
|
|
|
|
if (uri != NULL && !nonconform) { \
|
|
|
|
TT_FAIL(("Expected error parsing \"%s\"",s)); \
|
|
|
|
} else if (uri == NULL && nonconform) { \
|
|
|
|
TT_FAIL(("Couldn't parse nonconformant URI \"%s\"", \
|
|
|
|
s)); \
|
|
|
|
} \
|
|
|
|
if (uri) { \
|
|
|
|
tt_want(evhttp_uri_join(uri, url_tmp, \
|
|
|
|
sizeof(url_tmp))); \
|
|
|
|
evhttp_uri_free(uri); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2016-01-31 11:31:00 +00:00
|
|
|
#define UNI(s) do { \
|
|
|
|
uri = URI_PARSE(s); \
|
|
|
|
if (uri == NULL && unixsock) { \
|
|
|
|
TT_FAIL(("Couldn't parse unix socket URI \"%s\"", \
|
|
|
|
s)); \
|
|
|
|
} \
|
|
|
|
if (uri) { \
|
|
|
|
tt_want(evhttp_uri_join(uri, url_tmp, \
|
|
|
|
sizeof(url_tmp))); \
|
|
|
|
evhttp_uri_free(uri); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2011-02-13 00:41:22 -05:00
|
|
|
|
|
|
|
NCF("http://www.test.com/ why hello");
|
|
|
|
NCF("http://www.test.com/why-hello\x01");
|
|
|
|
NCF("http://www.test.com/why-hello?\x01");
|
|
|
|
NCF("http://www.test.com/why-hello#\x01");
|
2010-10-19 12:35:50 -04:00
|
|
|
BAD("http://www.\x01.test.com/why-hello");
|
|
|
|
BAD("http://www.%7test.com/why-hello");
|
2011-02-13 00:41:22 -05:00
|
|
|
NCF("http://www.test.com/why-hell%7o");
|
2010-10-19 12:35:50 -04:00
|
|
|
BAD("h%3ttp://www.test.com/why-hello");
|
2011-02-13 00:41:22 -05:00
|
|
|
NCF("http://www.test.com/why-hello%7");
|
|
|
|
NCF("http://www.test.com/why-hell%7o");
|
|
|
|
NCF("http://www.test.com/foo?ba%r");
|
|
|
|
NCF("http://www.test.com/foo#ba%r");
|
2010-10-19 12:35:50 -04:00
|
|
|
BAD("99:99/foo");
|
|
|
|
BAD("http://www.test.com:999x/");
|
|
|
|
BAD("http://www.test.com:x/");
|
|
|
|
BAD("http://[hello-there]/");
|
|
|
|
BAD("http://[::1]]/");
|
|
|
|
BAD("http://[::1/");
|
|
|
|
BAD("http://[foob/");
|
|
|
|
BAD("http://[/");
|
|
|
|
BAD("http://[ffff:ffff:ffff:ffff:Ffff:ffff:ffff:"
|
|
|
|
"ffff:ffff:ffff:ffff:ffff:ffff:ffff]/");
|
|
|
|
BAD("http://[vX.foo]/");
|
|
|
|
BAD("http://[vX.foo]/");
|
|
|
|
BAD("http://[v.foo]/");
|
|
|
|
BAD("http://[v5.fo%o]/");
|
|
|
|
BAD("http://[v5X]/");
|
|
|
|
BAD("http://[v5]/");
|
|
|
|
BAD("http://[]/");
|
|
|
|
BAD("http://f\x01red@www.example.com/");
|
|
|
|
BAD("http://f%0red@www.example.com/");
|
|
|
|
BAD("http://www.example.com:9999999999999999999999999999999999999/");
|
|
|
|
BAD("http://www.example.com:hihi/");
|
|
|
|
BAD("://www.example.com/");
|
|
|
|
|
2021-09-17 01:56:56 -04:00
|
|
|
#ifndef _WIN32
|
2016-01-31 11:31:00 +00:00
|
|
|
UNI("http://unix:/tmp/foobar/:/foo");
|
|
|
|
UNI("http://user:pass@unix:/tmp/foobar/:/foo");
|
|
|
|
UNI("http://unix:a:");
|
2021-09-17 01:56:56 -04:00
|
|
|
#endif
|
2016-01-31 11:31:00 +00:00
|
|
|
|
2010-10-19 12:35:50 -04:00
|
|
|
/* bad URIs: joining */
|
2010-10-21 14:41:12 -04:00
|
|
|
uri = evhttp_uri_new();
|
|
|
|
tt_want(0==evhttp_uri_set_host(uri, "www.example.com"));
|
2010-10-19 12:35:50 -04:00
|
|
|
tt_want(evhttp_uri_join(uri, url_tmp, sizeof(url_tmp)) != NULL);
|
|
|
|
/* not enough space: */
|
|
|
|
tt_want(evhttp_uri_join(uri, url_tmp, 3) == NULL);
|
|
|
|
/* host is set, but path doesn't start with "/": */
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(0==evhttp_uri_set_path(uri, "hi_mom"));
|
2010-08-08 16:46:39 +04:00
|
|
|
tt_want(evhttp_uri_join(uri, url_tmp, sizeof(url_tmp)) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
tt_want(evhttp_uri_join(uri, NULL, sizeof(url_tmp))==NULL);
|
|
|
|
tt_want(evhttp_uri_join(uri, url_tmp, 0)==NULL);
|
2010-10-21 14:41:12 -04:00
|
|
|
evhttp_uri_free(uri);
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("mailto:foo@bar");
|
2010-10-19 11:26:59 -04:00
|
|
|
tt_want(uri != NULL);
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(evhttp_uri_get_host(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(!strcmp(evhttp_uri_get_scheme(uri), "mailto"));
|
|
|
|
tt_want(!strcmp(evhttp_uri_get_path(uri), "foo@bar"));
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("mailto:foo@bar");
|
|
|
|
evhttp_uri_free(uri);
|
2010-08-08 16:46:39 +04:00
|
|
|
|
2010-10-21 14:53:21 -04:00
|
|
|
uri = evhttp_uri_new();
|
|
|
|
/* Bad URI usage: setting invalid values */
|
|
|
|
tt_want(-1 == evhttp_uri_set_scheme(uri,""));
|
|
|
|
tt_want(-1 == evhttp_uri_set_scheme(uri,"33"));
|
|
|
|
tt_want(-1 == evhttp_uri_set_scheme(uri,"hi!"));
|
|
|
|
tt_want(-1 == evhttp_uri_set_userinfo(uri,"hello@"));
|
|
|
|
tt_want(-1 == evhttp_uri_set_host(uri,"[1.2.3.4]"));
|
|
|
|
tt_want(-1 == evhttp_uri_set_host(uri,"["));
|
|
|
|
tt_want(-1 == evhttp_uri_set_host(uri,"www.[foo].com"));
|
|
|
|
tt_want(-1 == evhttp_uri_set_port(uri,-3));
|
|
|
|
tt_want(-1 == evhttp_uri_set_path(uri,"hello?world"));
|
|
|
|
tt_want(-1 == evhttp_uri_set_query(uri,"hello#world"));
|
|
|
|
tt_want(-1 == evhttp_uri_set_fragment(uri,"hello#world"));
|
|
|
|
/* Valid URI usage: setting valid values */
|
|
|
|
tt_want(0 == evhttp_uri_set_scheme(uri,"http"));
|
|
|
|
tt_want(0 == evhttp_uri_set_scheme(uri,NULL));
|
|
|
|
tt_want(0 == evhttp_uri_set_userinfo(uri,"username:pass"));
|
|
|
|
tt_want(0 == evhttp_uri_set_userinfo(uri,NULL));
|
|
|
|
tt_want(0 == evhttp_uri_set_host(uri,"www.example.com"));
|
|
|
|
tt_want(0 == evhttp_uri_set_host(uri,"1.2.3.4"));
|
|
|
|
tt_want(0 == evhttp_uri_set_host(uri,"[1:2:3:4::]"));
|
|
|
|
tt_want(0 == evhttp_uri_set_host(uri,"[v7.wobblewobble]"));
|
|
|
|
tt_want(0 == evhttp_uri_set_host(uri,NULL));
|
|
|
|
tt_want(0 == evhttp_uri_set_host(uri,""));
|
|
|
|
tt_want(0 == evhttp_uri_set_port(uri, -1));
|
|
|
|
tt_want(0 == evhttp_uri_set_port(uri, 80));
|
|
|
|
tt_want(0 == evhttp_uri_set_port(uri, 65535));
|
|
|
|
tt_want(0 == evhttp_uri_set_path(uri, ""));
|
|
|
|
tt_want(0 == evhttp_uri_set_path(uri, "/documents/public/index.html"));
|
|
|
|
tt_want(0 == evhttp_uri_set_path(uri, NULL));
|
|
|
|
tt_want(0 == evhttp_uri_set_query(uri, "key=val&key2=val2"));
|
|
|
|
tt_want(0 == evhttp_uri_set_query(uri, "keyvalblarg"));
|
|
|
|
tt_want(0 == evhttp_uri_set_query(uri, ""));
|
|
|
|
tt_want(0 == evhttp_uri_set_query(uri, NULL));
|
|
|
|
tt_want(0 == evhttp_uri_set_fragment(uri, ""));
|
|
|
|
tt_want(0 == evhttp_uri_set_fragment(uri, "here?i?am"));
|
|
|
|
tt_want(0 == evhttp_uri_set_fragment(uri, NULL));
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
|
|
|
/* Valid parsing */
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("http://www.test.com/?q=t%33est");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=t%33est") == 0);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("http://www.test.com/?q=t%33est");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("http://%77ww.test.com");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "%77ww.test.com") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("http://%77ww.test.com");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("http://www.test.com?q=test");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("http://www.test.com?q=test");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("http://www.test.com#fragment");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want_str_op(evhttp_uri_get_fragment(uri), ==, "fragment");
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("http://www.test.com#fragment");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("http://8000/");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "8000") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("http://8000/");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("http://:8000/");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == 8000);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("http://:8000/");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("http://www.test.com:/"); /* empty port */
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
|
|
|
|
tt_want_str_op(evhttp_uri_get_path(uri), ==, "/");
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("http://www.test.com/");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("http://www.test.com:"); /* empty port 2 */
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("http://www.test.com");
|
2010-08-08 16:46:39 +04:00
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("ftp://www.test.com/?q=test");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "ftp") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-08-08 16:46:39 +04:00
|
|
|
TT_URI("ftp://www.test.com/?q=test");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("ftp://[::1]:999/?q=test");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "ftp") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "[::1]") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == 999);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 11:26:59 -04:00
|
|
|
TT_URI("ftp://[::1]:999/?q=test");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("ftp://[ff00::127.0.0.1]/?q=test");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "ftp") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "[ff00::127.0.0.1]") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 11:26:59 -04:00
|
|
|
TT_URI("ftp://[ff00::127.0.0.1]/?q=test");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("ftp://[v99.not_(any:time)_soon]/?q=test");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "ftp") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "[v99.not_(any:time)_soon]") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("ftp://[v99.not_(any:time)_soon]/?q=test");
|
2010-10-19 11:26:59 -04:00
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("scheme://user:pass@foo.com:42/?q=test&s=some+thing#fragment");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "scheme") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_userinfo(uri), "user:pass") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "foo.com") == 0);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == 42);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=test&s=some+thing") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_fragment(uri), "fragment") == 0);
|
2010-08-08 16:46:39 +04:00
|
|
|
TT_URI("scheme://user:pass@foo.com:42/?q=test&s=some+thing#fragment");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("scheme://user@foo.com/#fragment");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "scheme") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_userinfo(uri), "user") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "foo.com") == 0);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_fragment(uri), "fragment") == 0);
|
2010-08-08 16:46:39 +04:00
|
|
|
TT_URI("scheme://user@foo.com/#fragment");
|
|
|
|
evhttp_uri_free(uri);
|
2010-10-19 11:26:59 -04:00
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("scheme://%75ser@foo.com/#frag@ment");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "scheme") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_userinfo(uri), "%75ser") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "foo.com") == 0);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_fragment(uri), "frag@ment") == 0);
|
2010-10-19 12:35:50 -04:00
|
|
|
TT_URI("scheme://%75ser@foo.com/#frag@ment");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("file:///some/path/to/the/file");
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "file") == 0);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "") == 0);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/some/path/to/the/file") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-08-08 16:46:39 +04:00
|
|
|
TT_URI("file:///some/path/to/the/file");
|
|
|
|
evhttp_uri_free(uri);
|
2010-10-19 11:26:59 -04:00
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("///some/path/to/the-file");
|
2010-10-19 11:26:59 -04:00
|
|
|
tt_want(uri != NULL);
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(evhttp_uri_get_scheme(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "") == 0);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/some/path/to/the-file") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 11:26:59 -04:00
|
|
|
TT_URI("///some/path/to/the-file");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("/s:ome/path/to/the-file?q=99#fred");
|
2010-10-19 11:26:59 -04:00
|
|
|
tt_want(uri != NULL);
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(evhttp_uri_get_scheme(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_host(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/s:ome/path/to/the-file") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=99") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_fragment(uri), "fred") == 0);
|
2010-10-19 11:26:59 -04:00
|
|
|
TT_URI("/s:ome/path/to/the-file?q=99#fred");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("relative/path/with/co:lon");
|
2010-10-19 11:26:59 -04:00
|
|
|
tt_want(uri != NULL);
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(evhttp_uri_get_scheme(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_host(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "relative/path/with/co:lon") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
2010-10-19 11:26:59 -04:00
|
|
|
TT_URI("relative/path/with/co:lon");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("bob?q=99&q2=q?33#fr?ed");
|
2010-10-19 11:26:59 -04:00
|
|
|
tt_want(uri != NULL);
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(evhttp_uri_get_scheme(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_host(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "bob") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=99&q2=q?33") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_fragment(uri), "fr?ed") == 0);
|
2010-10-19 11:26:59 -04:00
|
|
|
TT_URI("bob?q=99&q2=q?33#fr?ed");
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
2011-02-13 00:41:22 -05:00
|
|
|
uri = URI_PARSE("#fr?ed");
|
2010-10-19 11:26:59 -04:00
|
|
|
tt_want(uri != NULL);
|
2010-10-21 14:41:12 -04:00
|
|
|
tt_want(evhttp_uri_get_scheme(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_host(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
|
|
|
|
tt_want(evhttp_uri_get_query(uri) == NULL);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_fragment(uri), "fr?ed") == 0);
|
2010-10-19 11:26:59 -04:00
|
|
|
TT_URI("#fr?ed");
|
|
|
|
evhttp_uri_free(uri);
|
2020-10-27 01:40:34 +03:00
|
|
|
|
|
|
|
// EVHTTP_URI_HOST_STRIP_BRACKETS
|
|
|
|
uri = URI_PARSE_FLAGS("ftp://[ff00::127.0.0.1]/?q=test", EVHTTP_URI_HOST_STRIP_BRACKETS);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_scheme(uri), "ftp") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "ff00::127.0.0.1") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
|
|
|
|
tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
|
|
|
|
tt_want(evhttp_uri_get_userinfo(uri) == NULL);
|
|
|
|
tt_want(evhttp_uri_get_port(uri) == -1);
|
|
|
|
tt_want(evhttp_uri_get_fragment(uri) == NULL);
|
|
|
|
TT_URI("ftp://[ff00::127.0.0.1]/?q=test");
|
|
|
|
|
|
|
|
tt_want(0 == evhttp_uri_set_host(uri, "foo"));
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "foo") == 0);
|
|
|
|
TT_URI("ftp://foo/?q=test");
|
|
|
|
|
|
|
|
tt_want(0 == evhttp_uri_set_host(uri, "[ff00::127.0.0.1]"));
|
|
|
|
tt_want(strcmp(evhttp_uri_get_host(uri), "ff00::127.0.0.1") == 0);
|
|
|
|
TT_URI("ftp://[ff00::127.0.0.1]/?q=test");
|
|
|
|
|
|
|
|
evhttp_uri_free(uri);
|
|
|
|
|
|
|
|
#undef URI_PARSE_FLAGS
|
2011-02-13 00:41:22 -05:00
|
|
|
#undef URI_PARSE
|
|
|
|
#undef TT_URI
|
|
|
|
#undef BAD
|
2010-08-08 16:46:39 +04:00
|
|
|
}
|
|
|
|
|
2010-10-08 13:05:13 -04:00
|
|
|
static void
|
|
|
|
http_uriencode_test(void *ptr)
|
|
|
|
{
|
|
|
|
char *s=NULL, *s2=NULL;
|
|
|
|
size_t sz;
|
2013-03-01 12:01:42 +04:00
|
|
|
int bytes_decoded;
|
2010-10-08 13:05:13 -04:00
|
|
|
|
|
|
|
#define ENC(from,want,plus) do { \
|
|
|
|
s = evhttp_uriencode((from), -1, (plus)); \
|
|
|
|
tt_assert(s); \
|
|
|
|
tt_str_op(s,==,(want)); \
|
|
|
|
sz = -1; \
|
|
|
|
s2 = evhttp_uridecode((s), (plus), &sz); \
|
|
|
|
tt_assert(s2); \
|
|
|
|
tt_str_op(s2,==,(from)); \
|
|
|
|
tt_int_op(sz,==,strlen(from)); \
|
|
|
|
free(s); \
|
|
|
|
free(s2); \
|
|
|
|
s = s2 = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define DEC(from,want,dp) do { \
|
|
|
|
s = evhttp_uridecode((from),(dp),&sz); \
|
|
|
|
tt_assert(s); \
|
|
|
|
tt_str_op(s,==,(want)); \
|
|
|
|
tt_int_op(sz,==,strlen(want)); \
|
|
|
|
free(s); \
|
|
|
|
s = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define OLD_DEC(from,want) do { \
|
|
|
|
s = evhttp_decode_uri((from)); \
|
|
|
|
tt_assert(s); \
|
|
|
|
tt_str_op(s,==,(want)); \
|
|
|
|
free(s); \
|
|
|
|
s = NULL; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
ENC("Hello", "Hello",0);
|
|
|
|
ENC("99", "99",0);
|
|
|
|
ENC("", "",0);
|
|
|
|
ENC(
|
|
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-.~_",
|
|
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789-.~_",0);
|
|
|
|
ENC(" ", "%20",0);
|
|
|
|
ENC(" ", "+",1);
|
|
|
|
ENC("\xff\xf0\xe0", "%FF%F0%E0",0);
|
|
|
|
ENC("\x01\x19", "%01%19",1);
|
|
|
|
ENC("http://www.ietf.org/rfc/rfc3986.txt",
|
|
|
|
"http%3A%2F%2Fwww.ietf.org%2Frfc%2Frfc3986.txt",1);
|
|
|
|
|
|
|
|
ENC("1+2=3", "1%2B2%3D3",1);
|
|
|
|
ENC("1+2=3", "1%2B2%3D3",0);
|
|
|
|
|
|
|
|
/* Now try encoding with internal NULs. */
|
|
|
|
s = evhttp_uriencode("hello\0world", 11, 0);
|
|
|
|
tt_assert(s);
|
|
|
|
tt_str_op(s,==,"hello%00world");
|
|
|
|
free(s);
|
|
|
|
s = NULL;
|
|
|
|
|
2013-03-01 12:01:42 +04:00
|
|
|
/* Now try decoding just part of string. */
|
|
|
|
s = malloc(6 + 1 /* NUL byte */);
|
|
|
|
bytes_decoded = evhttp_decode_uri_internal("hello%20%20", 6, s, 0);
|
|
|
|
tt_assert(s);
|
|
|
|
tt_int_op(bytes_decoded,==,6);
|
|
|
|
tt_str_op(s,==,"hello%");
|
|
|
|
free(s);
|
|
|
|
s = NULL;
|
|
|
|
|
2010-10-08 13:05:13 -04:00
|
|
|
/* Now try out some decoding cases that we don't generate with
|
|
|
|
* encode_uri: Make sure that malformed stuff doesn't crash... */
|
|
|
|
DEC("%%xhello th+ere \xff",
|
|
|
|
"%%xhello th+ere \xff", 0);
|
|
|
|
/* Make sure plus decoding works */
|
|
|
|
DEC("plus+should%20work+", "plus should work ",1);
|
|
|
|
/* Try some lowercase hex */
|
|
|
|
DEC("%f0%a0%b0", "\xf0\xa0\xb0",1);
|
|
|
|
|
|
|
|
/* Try an internal NUL. */
|
|
|
|
sz = 0;
|
|
|
|
s = evhttp_uridecode("%00%00x%00%00", 1, &sz);
|
|
|
|
tt_int_op(sz,==,5);
|
|
|
|
tt_assert(!memcmp(s, "\0\0x\0\0", 5));
|
|
|
|
free(s);
|
|
|
|
s = NULL;
|
|
|
|
|
|
|
|
/* Try with size == NULL */
|
|
|
|
sz = 0;
|
|
|
|
s = evhttp_uridecode("%00%00x%00%00", 1, NULL);
|
|
|
|
tt_assert(!memcmp(s, "\0\0x\0\0", 5));
|
|
|
|
free(s);
|
|
|
|
s = NULL;
|
|
|
|
|
|
|
|
/* Test out the crazy old behavior of the deprecated
|
|
|
|
* evhttp_decode_uri */
|
|
|
|
OLD_DEC("http://example.com/normal+path/?key=val+with+spaces",
|
|
|
|
"http://example.com/normal+path/?key=val with spaces");
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (s)
|
|
|
|
free(s);
|
|
|
|
if (s2)
|
|
|
|
free(s2);
|
|
|
|
#undef ENC
|
|
|
|
#undef DEC
|
|
|
|
#undef OLD_DEC
|
2009-04-10 05:43:45 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 19:18:49 +00:00
|
|
|
static void
|
2010-04-23 23:13:26 -04:00
|
|
|
http_base_test(void *ptr)
|
2007-08-19 02:41:23 +00:00
|
|
|
{
|
2010-04-23 23:13:26 -04:00
|
|
|
struct event_base *base = NULL;
|
2010-02-18 17:41:15 -05:00
|
|
|
struct bufferevent *bev;
|
2010-03-05 12:47:46 -05:00
|
|
|
evutil_socket_t fd;
|
2007-11-26 19:18:49 +00:00
|
|
|
const char *http_request;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http;
|
|
|
|
|
2010-04-23 23:13:26 -04:00
|
|
|
test_ok = 0;
|
2010-11-03 15:04:44 -04:00
|
|
|
base = event_base_new();
|
2014-01-08 11:51:22 -05:00
|
|
|
tt_assert(base);
|
2013-01-27 02:17:02 +04:00
|
|
|
http = http_setup(&port, base, 0);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2007-08-19 02:41:23 +00:00
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2007-08-19 02:41:23 +00:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2010-11-03 15:04:44 -04:00
|
|
|
bev = bufferevent_socket_new(base, fd, 0);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
2010-11-03 15:04:44 -04:00
|
|
|
http_errorcb, base);
|
2007-08-19 02:41:23 +00:00
|
|
|
bufferevent_base_set(base, bev);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"GET /test HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2007-08-19 02:41:23 +00:00
|
|
|
event_base_dispatch(base);
|
|
|
|
|
|
|
|
bufferevent_free(bev);
|
2010-04-14 15:42:57 -04:00
|
|
|
evutil_closesocket(fd);
|
2007-08-19 02:41:23 +00:00
|
|
|
|
|
|
|
evhttp_free(http);
|
|
|
|
|
2010-04-23 23:13:26 -04:00
|
|
|
tt_int_op(test_ok, ==, 2);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-04-23 23:13:26 -04:00
|
|
|
end:
|
|
|
|
if (base)
|
|
|
|
event_base_free(base);
|
2007-08-19 02:41:23 +00:00
|
|
|
}
|
|
|
|
|
2008-04-27 19:41:26 +00:00
|
|
|
/*
|
|
|
|
* the server is just going to close the connection if it times out during
|
|
|
|
* reading the headers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_incomplete_readcb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
|
|
|
test_ok = -1;
|
2010-11-03 14:13:20 -04:00
|
|
|
event_base_loopexit(exit_base,NULL);
|
2008-04-27 19:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_incomplete_errorcb(struct bufferevent *bev, short what, void *arg)
|
|
|
|
{
|
2015-11-05 19:08:30 +03:00
|
|
|
/** For ssl */
|
|
|
|
if (what & BEV_EVENT_CONNECTED)
|
|
|
|
return;
|
|
|
|
|
2010-10-21 12:48:13 -04:00
|
|
|
if (what == (BEV_EVENT_READING|BEV_EVENT_EOF))
|
2008-04-27 19:41:26 +00:00
|
|
|
test_ok++;
|
|
|
|
else
|
|
|
|
test_ok = -2;
|
2010-11-03 14:13:20 -04:00
|
|
|
event_base_loopexit(exit_base,NULL);
|
2008-04-27 19:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_incomplete_writecb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
|
|
|
if (arg != NULL) {
|
2010-03-05 12:47:46 -05:00
|
|
|
evutil_socket_t fd = *(evutil_socket_t *)arg;
|
2008-04-27 19:41:26 +00:00
|
|
|
/* terminate the write side to simulate EOF */
|
2016-03-11 01:27:52 +03:00
|
|
|
shutdown(fd, EVUTIL_SHUT_WR);
|
2008-04-27 19:41:26 +00:00
|
|
|
}
|
2010-10-21 12:48:13 -04:00
|
|
|
if (evbuffer_get_length(bufferevent_get_output(bev)) == 0) {
|
2008-04-27 19:41:26 +00:00
|
|
|
/* enable reading of the reply */
|
|
|
|
bufferevent_enable(bev, EV_READ);
|
|
|
|
test_ok++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-11-05 19:08:30 +03:00
|
|
|
http_incomplete_test_(struct basic_test_data *data, int use_timeout, int ssl)
|
2008-04-27 19:41:26 +00:00
|
|
|
{
|
|
|
|
struct bufferevent *bev;
|
2010-03-05 12:47:46 -05:00
|
|
|
evutil_socket_t fd;
|
2008-04-27 19:41:26 +00:00
|
|
|
const char *http_request;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2008-04-27 19:41:26 +00:00
|
|
|
struct timeval tv_start, tv_end;
|
2020-09-06 15:33:32 +08:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, ssl);
|
2008-04-27 19:41:26 +00:00
|
|
|
|
2010-11-03 14:13:20 -04:00
|
|
|
exit_base = data->base;
|
2008-04-27 19:41:26 +00:00
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
evhttp_set_timeout(http, 1);
|
|
|
|
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2008-04-27 19:41:26 +00:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, fd, ssl, 0);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev,
|
2008-04-27 19:41:26 +00:00
|
|
|
http_incomplete_readcb, http_incomplete_writecb,
|
|
|
|
http_incomplete_errorcb, use_timeout ? NULL : &fd);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"GET /test HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_start, NULL);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-04-27 19:41:26 +00:00
|
|
|
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_end, NULL);
|
2008-05-12 17:16:47 +00:00
|
|
|
evutil_timersub(&tv_end, &tv_start, &tv_end);
|
2008-04-27 19:41:26 +00:00
|
|
|
|
2008-12-19 22:42:51 +00:00
|
|
|
bufferevent_free(bev);
|
2008-04-27 19:41:26 +00:00
|
|
|
if (use_timeout) {
|
2010-04-14 15:42:57 -04:00
|
|
|
evutil_closesocket(fd);
|
2019-01-29 21:12:33 +03:00
|
|
|
fd = EVUTIL_INVALID_SOCKET;
|
2008-04-27 19:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
evhttp_free(http);
|
|
|
|
|
|
|
|
if (use_timeout && tv_end.tv_sec >= 3) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("time");
|
2008-04-27 19:41:26 +00:00
|
|
|
} else if (!use_timeout && tv_end.tv_sec >= 1) {
|
|
|
|
/* we should be done immediately */
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("time");
|
2008-04-27 19:41:26 +00:00
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(test_ok, ==, 2);
|
|
|
|
end:
|
2014-01-08 13:02:37 -05:00
|
|
|
if (fd >= 0)
|
|
|
|
evutil_closesocket(fd);
|
2009-01-30 17:44:13 +00:00
|
|
|
}
|
2015-11-05 19:08:30 +03:00
|
|
|
static void http_incomplete_test(void *arg)
|
|
|
|
{ http_incomplete_test_(arg, 0, 0); }
|
|
|
|
static void http_incomplete_timeout_test(void *arg)
|
|
|
|
{ http_incomplete_test_(arg, 1, 0); }
|
2015-11-06 10:13:13 +03:00
|
|
|
|
2008-04-27 19:41:26 +00:00
|
|
|
|
2008-04-29 02:33:27 +00:00
|
|
|
/*
|
|
|
|
* the server is going to reply with chunked data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_chunked_readcb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
|
|
|
/* nothing here */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
|
|
|
|
{
|
2014-01-08 11:51:22 -05:00
|
|
|
struct evhttp_request *req = NULL;
|
|
|
|
|
2015-11-06 15:58:41 +03:00
|
|
|
/** SSL */
|
|
|
|
if (what & BEV_EVENT_CONNECTED)
|
|
|
|
return;
|
|
|
|
|
2008-04-29 02:33:27 +00:00
|
|
|
if (!test_ok)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
test_ok = -1;
|
|
|
|
|
2010-10-21 12:48:13 -04:00
|
|
|
if ((what & BEV_EVENT_EOF) != 0) {
|
2008-04-29 02:33:27 +00:00
|
|
|
const char *header;
|
2008-06-26 00:40:57 +00:00
|
|
|
enum message_read_status done;
|
2014-01-08 12:46:09 -05:00
|
|
|
req = evhttp_request_new(NULL, NULL);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-23 14:09:03 -07:00
|
|
|
/* req->kind = EVHTTP_RESPONSE; */
|
2012-02-29 15:07:33 -05:00
|
|
|
done = evhttp_parse_firstline_(req, bufferevent_get_input(bev));
|
2008-06-26 00:40:57 +00:00
|
|
|
if (done != ALL_DATA_READ)
|
|
|
|
goto out;
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2012-02-29 15:07:33 -05:00
|
|
|
done = evhttp_parse_headers_(req, bufferevent_get_input(bev));
|
2008-06-26 00:40:57 +00:00
|
|
|
if (done != ALL_DATA_READ)
|
2008-04-29 02:33:27 +00:00
|
|
|
goto out;
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
header = evhttp_find_header(evhttp_request_get_input_headers(req), "Transfer-Encoding");
|
2008-04-29 02:33:27 +00:00
|
|
|
if (header == NULL || strcmp(header, "chunked"))
|
|
|
|
goto out;
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
header = evhttp_find_header(evhttp_request_get_input_headers(req), "Connection");
|
2008-04-29 02:33:27 +00:00
|
|
|
if (header == NULL || strcmp(header, "close"))
|
|
|
|
goto out;
|
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
header = evbuffer_readln(bufferevent_get_input(bev), NULL, EVBUFFER_EOL_CRLF);
|
2008-04-29 02:33:27 +00:00
|
|
|
if (header == NULL)
|
|
|
|
goto out;
|
|
|
|
/* 13 chars */
|
2012-07-26 09:53:20 -04:00
|
|
|
if (strcmp(header, "d")) {
|
|
|
|
free((void*)header);
|
2008-04-29 02:33:27 +00:00
|
|
|
goto out;
|
2012-07-26 09:53:20 -04:00
|
|
|
}
|
|
|
|
free((void*)header);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 13),
|
2008-04-29 02:33:27 +00:00
|
|
|
"This is funny", 13))
|
|
|
|
goto out;
|
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
evbuffer_drain(bufferevent_get_input(bev), 13 + 2);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
header = evbuffer_readln(bufferevent_get_input(bev), NULL, EVBUFFER_EOL_CRLF);
|
2008-04-29 02:33:27 +00:00
|
|
|
if (header == NULL)
|
|
|
|
goto out;
|
|
|
|
/* 18 chars */
|
|
|
|
if (strcmp(header, "12"))
|
|
|
|
goto out;
|
|
|
|
free((char *)header);
|
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 18),
|
2008-04-29 02:33:27 +00:00
|
|
|
"but not hilarious.", 18))
|
|
|
|
goto out;
|
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
evbuffer_drain(bufferevent_get_input(bev), 18 + 2);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
header = evbuffer_readln(bufferevent_get_input(bev), NULL, EVBUFFER_EOL_CRLF);
|
2008-04-29 02:33:27 +00:00
|
|
|
if (header == NULL)
|
|
|
|
goto out;
|
|
|
|
/* 8 chars */
|
2012-07-26 09:53:20 -04:00
|
|
|
if (strcmp(header, "8")) {
|
|
|
|
free((void*)header);
|
2008-04-29 02:33:27 +00:00
|
|
|
goto out;
|
2012-07-26 09:53:20 -04:00
|
|
|
}
|
2008-04-29 02:33:27 +00:00
|
|
|
free((char *)header);
|
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
if (strncmp((char *)evbuffer_pullup(bufferevent_get_input(bev), 8),
|
2008-04-29 02:33:27 +00:00
|
|
|
"bwv 1052.", 8))
|
|
|
|
goto out;
|
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
evbuffer_drain(bufferevent_get_input(bev), 8 + 2);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2009-05-13 20:36:56 +00:00
|
|
|
header = evbuffer_readln(bufferevent_get_input(bev), NULL, EVBUFFER_EOL_CRLF);
|
2008-04-29 02:33:27 +00:00
|
|
|
if (header == NULL)
|
|
|
|
goto out;
|
|
|
|
/* 0 chars */
|
2012-07-26 09:53:20 -04:00
|
|
|
if (strcmp(header, "0")) {
|
|
|
|
free((void*)header);
|
2008-04-29 02:33:27 +00:00
|
|
|
goto out;
|
2012-07-26 09:53:20 -04:00
|
|
|
}
|
|
|
|
free((void *)header);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
|
|
|
test_ok = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2014-01-08 11:51:22 -05:00
|
|
|
if (req)
|
|
|
|
evhttp_request_free(req);
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(arg, NULL);
|
2008-04-29 02:33:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_chunked_writecb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
2010-10-21 12:48:13 -04:00
|
|
|
if (evbuffer_get_length(bufferevent_get_output(bev)) == 0) {
|
2008-04-29 02:33:27 +00:00
|
|
|
/* enable reading of the reply */
|
|
|
|
bufferevent_enable(bev, EV_READ);
|
|
|
|
test_ok++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-29 04:35:26 +00:00
|
|
|
static void
|
|
|
|
http_chunked_request_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_response_code(req) != HTTP_OK) {
|
2008-04-29 04:35:26 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req),
|
2008-04-29 04:35:26 +00:00
|
|
|
"Transfer-Encoding") == NULL) {
|
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_get_length(evhttp_request_get_input_buffer(req)) != 13 + 18 + 8) {
|
2008-04-29 04:35:26 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (strncmp((char *)evbuffer_pullup(evhttp_request_get_input_buffer(req), 13 + 18 + 8),
|
2008-04-29 04:35:26 +00:00
|
|
|
"This is funnybut not hilarious.bwv 1052",
|
|
|
|
13 + 18 + 8)) {
|
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-04-29 04:35:26 +00:00
|
|
|
test_ok = 1;
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(arg, NULL);
|
2008-04-29 04:35:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 23:23:42 +03:00
|
|
|
static void
|
|
|
|
http_send_chunk_test_read_cb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
|
|
|
}
|
|
|
|
/* sends 3 chunks */
|
|
|
|
static void
|
|
|
|
http_send_chunk_test_write_cb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *output = bufferevent_get_output(bev);
|
|
|
|
|
|
|
|
TT_BLATHER(("%s: called, test_ok=%i\n", __func__, test_ok));
|
|
|
|
|
|
|
|
if (test_ok < 3) {
|
|
|
|
size_t len = strlen(BASIC_REQUEST_BODY) + 1;
|
|
|
|
evbuffer_add_printf(output, "%x\r\n", (unsigned)len);
|
|
|
|
evbuffer_add(output, BASIC_REQUEST_BODY, strlen(BASIC_REQUEST_BODY));
|
|
|
|
/* to allow using evbuffer_readln() for simplicity */
|
|
|
|
evbuffer_add(output, "\n", 1);
|
|
|
|
evbuffer_add(output, "\r\n", 2);
|
|
|
|
} else if (test_ok == 3) {
|
|
|
|
/* last chunk */
|
|
|
|
evbuffer_add(output, "0\r\n\r\n", 5);
|
|
|
|
} else {
|
|
|
|
/* stop */
|
|
|
|
bufferevent_disable(bev, EV_WRITE);
|
|
|
|
bufferevent_enable(bev, EV_READ);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_ok++;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
http_send_chunk_test_error_cb(struct bufferevent *bev, short what, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *input = bufferevent_get_input(bev);
|
|
|
|
char *line;
|
|
|
|
|
|
|
|
TT_BLATHER(("%s: called\n", __func__));
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
/* suboptimal */
|
|
|
|
while (evbuffer_get_length(input)) {
|
|
|
|
size_t n_read_out = 0;
|
|
|
|
line = evbuffer_readln(input, &n_read_out, EVBUFFER_EOL_LF);
|
|
|
|
if (!line)
|
|
|
|
break;
|
|
|
|
/* don't bother about parsing http request,
|
|
|
|
* just count number of BASIC_REQUEST_BODY */
|
|
|
|
if (strcmp(line, BASIC_REQUEST_BODY) == 0) {
|
|
|
|
++test_ok;
|
|
|
|
}
|
|
|
|
free(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
event_base_loopexit(exit_base, NULL);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
http_send_chunk_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
struct bufferevent *bev = NULL;
|
|
|
|
evutil_socket_t fd;
|
|
|
|
const char *http_request;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0 /* ssl */);
|
|
|
|
|
|
|
|
exit_base = data->base;
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
|
|
|
|
|
|
|
bev = create_bev(data->base, fd, 0 /* ssl */, BEV_OPT_CLOSE_ON_FREE);
|
|
|
|
bufferevent_setcb(bev,
|
|
|
|
http_send_chunk_test_read_cb,
|
|
|
|
http_send_chunk_test_write_cb,
|
|
|
|
http_send_chunk_test_error_cb,
|
|
|
|
data->base);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"POST /chunked_input HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Transfer-Encoding: chunked\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* http_send_chunk_test_error_cb() find BASIC_REQUEST_BODY 3 times
|
|
|
|
*/
|
|
|
|
tt_int_op(test_ok, ==, 3);
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (bev)
|
|
|
|
bufferevent_free(bev);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
2008-04-29 02:33:27 +00:00
|
|
|
static void
|
2015-11-06 15:58:41 +03:00
|
|
|
http_chunk_out_test_impl(void *arg, int ssl)
|
2008-04-29 02:33:27 +00:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2020-06-25 21:56:31 +03:00
|
|
|
struct bufferevent *bev = NULL;
|
2010-03-05 12:47:46 -05:00
|
|
|
evutil_socket_t fd;
|
2008-04-29 02:33:27 +00:00
|
|
|
const char *http_request;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2008-04-29 02:33:27 +00:00
|
|
|
struct timeval tv_start, tv_end;
|
2008-04-29 04:35:26 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2008-06-26 00:40:57 +00:00
|
|
|
int i;
|
2020-09-06 15:33:32 +08:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, ssl);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
exit_base = data->base;
|
2008-04-29 02:33:27 +00:00
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, fd, ssl, BEV_OPT_CLOSE_ON_FREE);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev,
|
2008-04-29 02:33:27 +00:00
|
|
|
http_chunked_readcb, http_chunked_writecb,
|
2010-11-03 14:31:23 -04:00
|
|
|
http_chunked_errorcb, data->base);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
|
|
|
http_request =
|
|
|
|
"GET /chunked HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_start, NULL);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2008-12-19 22:42:51 +00:00
|
|
|
bufferevent_free(bev);
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = NULL;
|
2008-12-19 22:42:51 +00:00
|
|
|
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_end, NULL);
|
2008-05-12 17:16:47 +00:00
|
|
|
evutil_timersub(&tv_end, &tv_start, &tv_end);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(tv_end.tv_sec, <, 1);
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(test_ok, ==, 2);
|
2008-04-29 04:35:26 +00:00
|
|
|
|
|
|
|
/* now try again with the regular connection object */
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, -1, ssl, BEV_OPT_CLOSE_ON_FREE);
|
2015-11-06 15:58:41 +03:00
|
|
|
evcon = evhttp_connection_base_bufferevent_new(
|
|
|
|
data->base, NULL, bev, "127.0.0.1", port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2008-04-29 04:35:26 +00:00
|
|
|
|
2008-06-26 00:40:57 +00:00
|
|
|
/* make two requests to check the keepalive behavior */
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
test_ok = 0;
|
2020-06-25 21:56:31 +03:00
|
|
|
req = evhttp_request_new(http_chunked_request_done, data->base);
|
2008-04-29 04:35:26 +00:00
|
|
|
|
2008-06-26 00:40:57 +00:00
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2008-04-29 04:35:26 +00:00
|
|
|
|
2008-06-26 00:40:57 +00:00
|
|
|
/* We give ownership of the request to the connection */
|
2020-06-25 21:56:31 +03:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/chunked") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-06-26 00:40:57 +00:00
|
|
|
}
|
2008-04-29 04:35:26 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-06-26 00:40:57 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(test_ok == 1);
|
2008-04-29 04:35:26 +00:00
|
|
|
}
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2008-04-29 02:33:27 +00:00
|
|
|
}
|
2015-11-06 15:58:41 +03:00
|
|
|
static void http_chunk_out_test(void *arg)
|
2017-03-14 13:21:16 +03:00
|
|
|
{ http_chunk_out_test_impl(arg, 0); }
|
2008-04-29 02:33:27 +00:00
|
|
|
|
2008-07-02 06:08:16 +00:00
|
|
|
static void
|
2015-11-15 00:05:00 +03:00
|
|
|
http_stream_out_test_impl(void *arg, int ssl)
|
2008-07-02 06:08:16 +00:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2008-07-02 06:08:16 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2015-11-15 00:05:00 +03:00
|
|
|
struct bufferevent *bev;
|
2020-09-06 15:33:32 +08:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, ssl);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-07-02 06:08:16 +00:00
|
|
|
test_ok = 0;
|
2010-11-03 14:31:23 -04:00
|
|
|
exit_base = data->base;
|
2008-07-02 06:08:16 +00:00
|
|
|
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, -1, ssl, 0);
|
2015-11-15 00:05:00 +03:00
|
|
|
evcon = evhttp_connection_base_bufferevent_new(
|
|
|
|
data->base, NULL, bev, "127.0.0.1", port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2008-07-02 06:08:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we want to schedule a request to the HTTP
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_done,
|
|
|
|
(void *)"This is funnybut not hilarious.bwv 1052");
|
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2008-07-02 06:08:16 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/streamed")
|
|
|
|
== -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-07-02 06:08:16 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-07-02 06:08:16 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2008-07-02 06:08:16 +00:00
|
|
|
}
|
2015-11-15 00:05:00 +03:00
|
|
|
static void http_stream_out_test(void *arg)
|
2017-03-14 13:21:16 +03:00
|
|
|
{ http_stream_out_test_impl(arg, 0); }
|
2008-07-02 06:08:16 +00:00
|
|
|
|
2008-06-02 05:45:26 +00:00
|
|
|
static void
|
|
|
|
http_stream_in_chunk(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evbuffer *reply = arg;
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evhttp_request_get_response_code(req) != HTTP_OK) {
|
2008-06-02 05:45:26 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
evbuffer_add_buffer(reply, evhttp_request_get_input_buffer(req));
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_stream_in_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2010-11-03 15:14:29 -04:00
|
|
|
if (evbuffer_get_length(evhttp_request_get_input_buffer(req)) != 0) {
|
2008-06-02 05:45:26 +00:00
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(exit_base, NULL);
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes a request and reads the response in chunks.
|
|
|
|
*/
|
|
|
|
static void
|
2012-02-29 15:07:32 -05:00
|
|
|
http_stream_in_test_(struct basic_test_data *data, char const *url,
|
2008-06-02 05:45:26 +00:00
|
|
|
size_t expected_len, char const *expected)
|
|
|
|
{
|
|
|
|
struct evhttp_connection *evcon;
|
|
|
|
struct evbuffer *reply = evbuffer_new();
|
|
|
|
struct evhttp_request *req = NULL;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2008-06-02 05:45:26 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
exit_base = data->base;
|
2008-06-02 05:45:26 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL,"127.0.0.1", port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2008-06-02 05:45:26 +00:00
|
|
|
|
|
|
|
req = evhttp_request_new(http_stream_in_done, reply);
|
|
|
|
evhttp_request_set_chunked_cb(req, http_stream_in_chunk);
|
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, url) == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-06-02 05:45:26 +00:00
|
|
|
|
|
|
|
if (evbuffer_get_length(reply) != expected_len) {
|
2010-10-05 14:29:48 -04:00
|
|
|
TT_DIE(("reply length %lu; expected %lu; FAILED (%s)\n",
|
2010-10-21 12:48:13 -04:00
|
|
|
(unsigned long)evbuffer_get_length(reply),
|
2010-10-05 14:29:48 -04:00
|
|
|
(unsigned long)expected_len,
|
|
|
|
(char*)evbuffer_pullup(reply, -1)));
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(evbuffer_pullup(reply, -1), expected, expected_len) != 0) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Memory mismatch");
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
test_ok = 1;
|
|
|
|
end:
|
|
|
|
if (reply)
|
|
|
|
evbuffer_free(reply);
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 14:31:23 -04:00
|
|
|
http_stream_in_test(void *arg)
|
2008-06-02 05:45:26 +00:00
|
|
|
{
|
2012-02-29 15:07:32 -05:00
|
|
|
http_stream_in_test_(arg, "/chunked", 13 + 18 + 8,
|
2008-06-02 05:45:26 +00:00
|
|
|
"This is funnybut not hilarious.bwv 1052");
|
|
|
|
|
2012-02-29 15:07:32 -05:00
|
|
|
http_stream_in_test_(arg, "/test", strlen(BASIC_REQUEST_BODY),
|
2008-07-02 06:08:16 +00:00
|
|
|
BASIC_REQUEST_BODY);
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_stream_in_cancel_chunk(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2010-11-03 15:14:29 -04:00
|
|
|
tt_int_op(evhttp_request_get_response_code(req), ==, HTTP_OK);
|
2008-06-02 05:45:26 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
2008-06-02 05:45:26 +00:00
|
|
|
evhttp_cancel_request(req);
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(arg, NULL);
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_stream_in_cancel_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
/* should never be called */
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_fail_msg("In cancel done");
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 14:31:23 -04:00
|
|
|
http_stream_in_cancel_test(void *arg)
|
2008-06-02 05:45:26 +00:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2008-06-02 05:45:26 +00:00
|
|
|
struct evhttp_connection *evcon;
|
|
|
|
struct evhttp_request *req = NULL;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2008-06-02 05:45:26 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2008-06-02 05:45:26 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
req = evhttp_request_new(http_stream_in_cancel_done, data->base);
|
2008-06-02 05:45:26 +00:00
|
|
|
evhttp_request_set_chunked_cb(req, http_stream_in_cancel_chunk);
|
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/chunked") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-06-02 05:45:26 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
test_ok = 1;
|
|
|
|
end:
|
2008-06-02 05:45:26 +00:00
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
evhttp_free(http);
|
2009-01-30 17:44:13 +00:00
|
|
|
|
2008-06-02 05:45:26 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 01:40:05 -04:00
|
|
|
static void
|
|
|
|
http_connection_fail_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2015-11-15 00:08:24 +03:00
|
|
|
struct evhttp_connection *evcon = arg;
|
|
|
|
struct event_base *base = evhttp_connection_get_base(evcon);
|
2013-02-14 09:54:56 -08:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
/* An ENETUNREACH error results in an unrecoverable
|
|
|
|
* evhttp_connection error (see evhttp_connection_fail_()). The
|
|
|
|
* connection will be reset, and the user will be notified with a NULL
|
|
|
|
* req parameter. */
|
|
|
|
tt_assert(!req);
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
evhttp_connection_free(evcon);
|
2013-02-14 09:54:56 -08:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
test_ok = 1;
|
2011-05-23 01:40:05 -04:00
|
|
|
|
|
|
|
end:
|
2015-11-15 00:08:24 +03:00
|
|
|
event_base_loopexit(base, NULL);
|
2011-05-23 01:40:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Test unrecoverable evhttp_connection errors by generating an ENETUNREACH
|
|
|
|
* error on connection. */
|
|
|
|
static void
|
2015-11-15 00:08:24 +03:00
|
|
|
http_connection_fail_test_impl(void *arg, int ssl)
|
2011-05-23 01:40:05 -04:00
|
|
|
{
|
2015-11-15 00:08:24 +03:00
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
|
|
|
struct bufferevent *bev;
|
2020-09-06 15:33:32 +08:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, ssl);
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
exit_base = data->base;
|
|
|
|
test_ok = 0;
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
/* auto detect a port */
|
|
|
|
evhttp_free(http);
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, -1, ssl, 0);
|
2015-11-15 00:08:24 +03:00
|
|
|
/* Pick an unroutable address. This administratively scoped multicast
|
|
|
|
* address should do when working with TCP. */
|
|
|
|
evcon = evhttp_connection_base_bufferevent_new(
|
|
|
|
data->base, NULL, bev, "239.10.20.30", 80);
|
|
|
|
tt_assert(evcon);
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
/*
|
|
|
|
* At this point, we want to schedule an HTTP GET request
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
req = evhttp_request_new(http_connection_fail_done, evcon);
|
|
|
|
tt_assert(req);
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
event_base_dispatch(data->base);
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2015-11-15 00:08:24 +03:00
|
|
|
tt_int_op(test_ok, ==, 1);
|
2011-05-23 01:40:05 -04:00
|
|
|
|
|
|
|
end:
|
2015-11-15 00:08:24 +03:00
|
|
|
;
|
2011-05-23 01:40:05 -04:00
|
|
|
}
|
2015-11-15 00:08:24 +03:00
|
|
|
static void http_connection_fail_test(void *arg)
|
2017-03-14 13:21:16 +03:00
|
|
|
{ http_connection_fail_test_impl(arg, 0); }
|
2011-05-23 01:40:05 -04:00
|
|
|
|
2008-04-27 20:04:33 +00:00
|
|
|
static void
|
|
|
|
http_connection_retry_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(req);
|
2010-11-03 15:14:29 -04:00
|
|
|
tt_int_op(evhttp_request_get_response_code(req), !=, HTTP_OK);
|
|
|
|
if (evhttp_find_header(evhttp_request_get_input_headers(req), "Content-Type") != NULL) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("(content type)\n");
|
2008-04-27 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 15:14:29 -04:00
|
|
|
tt_uint_op(evbuffer_get_length(evhttp_request_get_input_buffer(req)), ==, 0);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-04-27 20:04:33 +00:00
|
|
|
test_ok = 1;
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(arg,NULL);
|
2008-04-27 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 11:17:07 +03:00
|
|
|
struct http_server
|
|
|
|
{
|
|
|
|
ev_uint16_t port;
|
|
|
|
int ssl;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http;
|
2015-11-05 11:17:07 +03:00
|
|
|
};
|
2010-11-03 14:31:23 -04:00
|
|
|
static struct event_base *http_make_web_server_base=NULL;
|
2008-04-27 20:04:33 +00:00
|
|
|
static void
|
2010-03-05 12:47:46 -05:00
|
|
|
http_make_web_server(evutil_socket_t fd, short what, void *arg)
|
2008-04-27 20:04:33 +00:00
|
|
|
{
|
2015-11-05 11:17:07 +03:00
|
|
|
struct http_server *hs = (struct http_server *)arg;
|
2020-09-06 15:33:32 +08:00
|
|
|
hs->http = http_setup(&hs->port, http_make_web_server_base, hs->ssl);
|
2008-04-27 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 12:39:35 +03:00
|
|
|
static void
|
2018-10-22 23:38:42 +03:00
|
|
|
http_simple_test_impl(void *arg, int ssl, int dirty, const char *uri)
|
2015-11-05 12:39:35 +03:00
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
|
|
|
struct bufferevent *bev;
|
2017-05-01 21:56:27 +03:00
|
|
|
struct http_server hs = { 0, ssl, NULL, };
|
2020-09-06 15:33:32 +08:00
|
|
|
struct evhttp *http = http_setup(&hs.port, data->base, ssl);
|
2015-11-05 12:39:35 +03:00
|
|
|
|
|
|
|
exit_base = data->base;
|
|
|
|
test_ok = 0;
|
|
|
|
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, -1, ssl, 0);
|
2016-11-19 17:53:38 +03:00
|
|
|
#ifdef EVENT__HAVE_OPENSSL
|
|
|
|
bufferevent_openssl_set_allow_dirty_shutdown(bev, dirty);
|
|
|
|
#endif
|
2020-09-15 18:15:24 +08:00
|
|
|
#ifdef EVENT__HAVE_MBEDTLS
|
|
|
|
bufferevent_mbedtls_set_allow_dirty_shutdown(bev, dirty);
|
|
|
|
#endif
|
2016-11-19 17:53:38 +03:00
|
|
|
|
2015-11-05 12:39:35 +03:00
|
|
|
evcon = evhttp_connection_base_bufferevent_new(
|
|
|
|
data->base, NULL, bev, "127.0.0.1", hs.port);
|
|
|
|
tt_assert(evcon);
|
|
|
|
evhttp_connection_set_local_address(evcon, "127.0.0.1");
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_done, (void*) BASIC_REQUEST_BODY);
|
|
|
|
tt_assert(req);
|
|
|
|
|
2018-10-22 23:38:42 +03:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, uri) == -1)
|
2015-11-05 12:39:35 +03:00
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
tt_int_op(test_ok, ==, 1);
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
2015-11-06 10:13:13 +03:00
|
|
|
static void http_simple_test(void *arg)
|
2018-10-22 23:38:42 +03:00
|
|
|
{ http_simple_test_impl(arg, 0, 0, "/test"); }
|
|
|
|
static void http_simple_nonconformant_test(void *arg)
|
|
|
|
{ http_simple_test_impl(arg, 0, 0, "/test nonconformant"); }
|
2015-11-05 12:39:35 +03:00
|
|
|
|
2008-04-27 20:04:33 +00:00
|
|
|
static void
|
2015-11-05 11:17:07 +03:00
|
|
|
http_connection_retry_test_basic(void *arg, const char *addr, struct evdns_base *dns_base, int ssl)
|
2008-04-27 20:04:33 +00:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2008-04-27 20:04:33 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
|
|
|
struct timeval tv, tv_start, tv_end;
|
2015-11-05 11:17:07 +03:00
|
|
|
struct bufferevent *bev;
|
2017-05-01 21:56:27 +03:00
|
|
|
struct http_server hs = { 0, ssl, NULL, };
|
2020-09-06 15:33:32 +08:00
|
|
|
struct evhttp *http = http_setup(&hs.port, data->base, ssl);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
exit_base = data->base;
|
2008-04-27 20:04:33 +00:00
|
|
|
test_ok = 0;
|
|
|
|
|
2010-09-03 18:48:31 -04:00
|
|
|
/* auto detect a port */
|
2008-04-27 20:04:33 +00:00
|
|
|
evhttp_free(http);
|
|
|
|
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, -1, ssl, 0);
|
2015-11-05 11:17:07 +03:00
|
|
|
evcon = evhttp_connection_base_bufferevent_new(data->base, dns_base, bev, addr, hs.port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2015-01-01 06:27:31 +03:00
|
|
|
if (dns_base)
|
|
|
|
tt_assert(!evhttp_connection_set_flags(evcon, EVHTTP_CON_REUSE_CONNECTED_ADDR));
|
2008-04-27 20:04:33 +00:00
|
|
|
|
|
|
|
evhttp_connection_set_timeout(evcon, 1);
|
|
|
|
/* also bind to local host */
|
|
|
|
evhttp_connection_set_local_address(evcon, "127.0.0.1");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we want to schedule an HTTP GET request
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
req = evhttp_request_new(http_connection_retry_done, data->base);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(req);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-04-27 20:04:33 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
|
|
|
"/?arg=val") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-04-27 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_start, NULL);
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_end, NULL);
|
2008-05-12 17:16:47 +00:00
|
|
|
evutil_timersub(&tv_end, &tv_start, &tv_end);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(tv_end.tv_sec, <, 1);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(test_ok, ==, 1);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now test the same but with retries
|
|
|
|
*/
|
|
|
|
test_ok = 0;
|
2014-11-15 20:35:40 +03:00
|
|
|
/** Shutdown dns server, to test conn_address reusing */
|
|
|
|
if (dns_base)
|
|
|
|
regress_clean_dnsserver();
|
2008-04-27 20:04:33 +00:00
|
|
|
|
2012-01-24 14:33:10 -05:00
|
|
|
{
|
2012-04-01 00:21:55 -04:00
|
|
|
const struct timeval tv_timeout = { 0, 500000 };
|
|
|
|
const struct timeval tv_retry = { 0, 500000 };
|
2012-01-24 14:33:10 -05:00
|
|
|
evhttp_connection_set_timeout_tv(evcon, &tv_timeout);
|
|
|
|
evhttp_connection_set_initial_retry_tv(evcon, &tv_retry);
|
|
|
|
}
|
2008-04-27 20:04:33 +00:00
|
|
|
evhttp_connection_set_retries(evcon, 1);
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
req = evhttp_request_new(http_connection_retry_done, data->base);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(req);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-04-27 20:04:33 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
|
|
|
"/?arg=val") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-04-27 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_start, NULL);
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_end, NULL);
|
2012-01-24 14:33:10 -05:00
|
|
|
|
2012-04-01 00:21:55 -04:00
|
|
|
/* fails fast, .5 sec to wait to retry, fails fast again. */
|
|
|
|
test_timeval_diff_leq(&tv_start, &tv_end, 500, 200);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(test_ok == 1);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* now test the same but with retries and give it a web server
|
|
|
|
* at the end
|
|
|
|
*/
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
evhttp_connection_set_timeout(evcon, 1);
|
|
|
|
evhttp_connection_set_retries(evcon, 3);
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
req = evhttp_request_new(http_dispatcher_test_done, data->base);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(req);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
|
|
|
/* Add the information that we care about */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-04-27 20:04:33 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET,
|
|
|
|
"/?arg=val") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-04-27 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 14:33:10 -05:00
|
|
|
/* start up a web server .2 seconds after the connection tried
|
2008-04-27 20:04:33 +00:00
|
|
|
* to send a request
|
|
|
|
*/
|
Remove compat/sys/_time.h
I've gone through everything that it declared to see where it was used,
and it seems that we probably don't need it anywhere.
Here's what it declared, and why I think we're okay dropping it.
o struct timeval {}
(Used all over, and we can't really get away with declaring it ourselves;
we need the same definition the system uses. If we can't find struct
timeval, we're pretty much sunk.)
o struct timespec {}
(Used in event.c, evdns.c, kqueue.c, evport.c. Of these,
kqueue.c and event.c include sys/_time.h. event.c conditions its use on
_EVENT_HAVE_CLOCK_GETTIME, and kqueue() only works if timespec is defined.)
o TIMEVAL_TO_TIMESPEC
(Used in kqueue.c, but every place with kqueue has sys/time.h)
o struct timezone {}
(event2/util.h has a forward declaration; only evutil.c references it and
doesn't look at its contents.)
o timerclear, timerisset, timercmp, timeradd, timersub
(Everything now uses the evutil_timer* variants.)
o ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF, struct itemerval
(These are only used in test/regress.c, which does not include _time.h)
o CLOCK_REALTIME
(Only used in evdns.c, which does not include _time.h)
o TIMESPEC_TO_TIMEVAL
o DST_*
o timespecclear, timespecisset, timespeccmp, timespecadd, timespecsub
o struct clockinfo {}
o CLOCK_VIRTUAL, CLOCK_PROF
o TIMER_RELTIME, TIMER_ABSTIME
(unused)
svn:r1494
2009-11-03 19:54:56 +00:00
|
|
|
evutil_timerclear(&tv);
|
2012-01-24 14:33:10 -05:00
|
|
|
tv.tv_usec = 200000;
|
2010-11-03 14:31:23 -04:00
|
|
|
http_make_web_server_base = data->base;
|
2015-11-05 11:17:07 +03:00
|
|
|
event_base_once(data->base, -1, EV_TIMEOUT, http_make_web_server, &hs, &tv);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_start, NULL);
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-06-24 16:39:45 +00:00
|
|
|
evutil_gettimeofday(&tv_end, NULL);
|
2012-01-24 14:33:10 -05:00
|
|
|
/* We'll wait twice as long as we did last time. */
|
2012-04-01 00:21:55 -04:00
|
|
|
test_timeval_diff_leq(&tv_start, &tv_end, 1000, 400);
|
2008-04-27 20:04:33 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(test_ok, ==, 1);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
2016-03-25 11:04:51 +03:00
|
|
|
evhttp_free(hs.http);
|
2008-04-27 20:04:33 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 20:35:40 +03:00
|
|
|
static void
|
2015-11-05 11:17:07 +03:00
|
|
|
http_connection_retry_conn_address_test_impl(void *arg, int ssl)
|
2014-11-15 20:35:40 +03:00
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t portnum = 0;
|
2015-08-18 21:30:48 +03:00
|
|
|
struct evdns_base *dns_base = NULL;
|
2014-11-15 20:35:40 +03:00
|
|
|
char address[64];
|
|
|
|
|
2020-05-21 12:46:20 +03:00
|
|
|
tt_assert(regress_dnsserver(data->base, &portnum, search_table, NULL));
|
2014-11-15 20:35:40 +03:00
|
|
|
dns_base = evdns_base_new(data->base, 0/* init name servers */);
|
|
|
|
tt_assert(dns_base);
|
|
|
|
|
|
|
|
/* Add ourself as the only nameserver, and make sure we really are
|
|
|
|
* the only nameserver. */
|
|
|
|
evutil_snprintf(address, sizeof(address), "127.0.0.1:%d", portnum);
|
|
|
|
evdns_base_nameserver_ip_add(dns_base, address);
|
|
|
|
|
2015-11-05 11:17:07 +03:00
|
|
|
http_connection_retry_test_basic(arg, "localhost", dns_base, ssl);
|
2014-11-15 20:35:40 +03:00
|
|
|
|
|
|
|
end:
|
|
|
|
if (dns_base)
|
|
|
|
evdns_base_free(dns_base, 0);
|
2015-11-05 11:17:07 +03:00
|
|
|
/** dnsserver will be cleaned in http_connection_retry_test_basic() */
|
2014-11-15 20:35:40 +03:00
|
|
|
}
|
2015-11-05 11:17:07 +03:00
|
|
|
static void http_connection_retry_conn_address_test(void *arg)
|
2017-03-14 13:21:16 +03:00
|
|
|
{ http_connection_retry_conn_address_test_impl(arg, 0); }
|
2014-11-15 20:35:40 +03:00
|
|
|
|
|
|
|
static void
|
2015-11-05 11:17:07 +03:00
|
|
|
http_connection_retry_test_impl(void *arg, int ssl)
|
2014-11-15 20:35:40 +03:00
|
|
|
{
|
2017-03-14 13:21:16 +03:00
|
|
|
http_connection_retry_test_basic(arg, "127.0.0.1", NULL, ssl);
|
2014-11-15 20:35:40 +03:00
|
|
|
}
|
2015-11-05 11:17:07 +03:00
|
|
|
static void
|
|
|
|
http_connection_retry_test(void *arg)
|
2017-03-14 13:21:16 +03:00
|
|
|
{ http_connection_retry_test_impl(arg, 0); }
|
2014-11-15 20:35:40 +03:00
|
|
|
|
2008-04-29 00:24:00 +00:00
|
|
|
static void
|
2009-01-30 17:44:13 +00:00
|
|
|
http_primitives(void *ptr)
|
2008-04-29 00:24:00 +00:00
|
|
|
{
|
2009-01-30 17:44:13 +00:00
|
|
|
char *escaped = NULL;
|
2012-07-26 09:35:43 -04:00
|
|
|
struct evhttp *http = NULL;
|
2008-04-29 00:24:00 +00:00
|
|
|
|
|
|
|
escaped = evhttp_htmlescape("<script>");
|
2012-07-26 09:35:43 -04:00
|
|
|
tt_assert(escaped);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_str_op(escaped, ==, "<script>");
|
2008-04-29 00:24:00 +00:00
|
|
|
free(escaped);
|
|
|
|
|
|
|
|
escaped = evhttp_htmlescape("\"\'&");
|
2012-07-26 09:35:43 -04:00
|
|
|
tt_assert(escaped);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_str_op(escaped, ==, ""'&");
|
2008-04-29 00:24:00 +00:00
|
|
|
|
2009-04-17 01:03:07 +00:00
|
|
|
http = evhttp_new(NULL);
|
2012-07-26 09:35:43 -04:00
|
|
|
tt_assert(http);
|
2016-03-25 11:04:51 +03:00
|
|
|
tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, http), ==, 0);
|
|
|
|
tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, http), ==, -1);
|
2009-04-17 01:03:07 +00:00
|
|
|
tt_int_op(evhttp_del_cb(http, "/test"), ==, 0);
|
|
|
|
tt_int_op(evhttp_del_cb(http, "/test"), ==, -1);
|
2016-03-25 11:04:51 +03:00
|
|
|
tt_int_op(evhttp_set_cb(http, "/test", http_basic_cb, http), ==, 0);
|
2009-04-17 01:03:07 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
if (escaped)
|
|
|
|
free(escaped);
|
2012-07-26 09:35:43 -04:00
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2008-04-29 00:24:00 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 01:30:06 +00:00
|
|
|
static void
|
2010-11-03 14:31:23 -04:00
|
|
|
http_multi_line_header_test(void *arg)
|
2008-06-29 01:30:06 +00:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2009-01-30 17:44:13 +00:00
|
|
|
struct bufferevent *bev= NULL;
|
2019-01-29 21:12:33 +03:00
|
|
|
evutil_socket_t fd = EVUTIL_INVALID_SOCKET;
|
2008-06-29 01:30:06 +00:00
|
|
|
const char *http_start_request;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2016-03-25 11:22:43 +03:00
|
|
|
exit_base = data->base;
|
2008-06-29 01:30:06 +00:00
|
|
|
test_ok = 0;
|
|
|
|
|
2014-01-08 11:51:22 -05:00
|
|
|
tt_ptr_op(http, !=, NULL);
|
|
|
|
|
2008-06-29 01:30:06 +00:00
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2014-01-08 11:51:22 -05:00
|
|
|
|
2008-06-29 01:30:06 +00:00
|
|
|
/* Stupid thing to send a request */
|
2010-11-03 14:31:23 -04:00
|
|
|
bev = bufferevent_socket_new(data->base, fd, 0);
|
2014-01-08 11:51:22 -05:00
|
|
|
tt_ptr_op(bev, !=, NULL);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
2010-11-03 14:31:23 -04:00
|
|
|
http_errorcb, data->base);
|
2008-06-29 01:30:06 +00:00
|
|
|
|
|
|
|
http_start_request =
|
|
|
|
"GET /test HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
2012-11-16 11:38:53 -05:00
|
|
|
"X-Multi-Extra-WS: libevent \r\n"
|
|
|
|
"\t\t\t2.1 \r\n"
|
2008-06-29 01:30:06 +00:00
|
|
|
"X-Multi: aaaaaaaa\r\n"
|
|
|
|
" a\r\n"
|
|
|
|
"\tEND\r\n"
|
|
|
|
"X-Last: last\r\n"
|
|
|
|
"\r\n";
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-06-29 01:30:06 +00:00
|
|
|
bufferevent_write(bev, http_start_request, strlen(http_start_request));
|
2012-11-16 11:38:53 -05:00
|
|
|
found_multi = found_multi2 = 0;
|
2008-06-29 01:30:06 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2012-11-16 11:38:53 -05:00
|
|
|
tt_int_op(found_multi, ==, 1);
|
|
|
|
tt_int_op(found_multi2, ==, 1);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_int_op(test_ok, ==, 4);
|
|
|
|
end:
|
|
|
|
if (bev)
|
|
|
|
bufferevent_free(bev);
|
|
|
|
if (fd >= 0)
|
2010-04-14 15:42:57 -04:00
|
|
|
evutil_closesocket(fd);
|
2009-01-30 17:44:13 +00:00
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2008-06-29 01:30:06 +00:00
|
|
|
}
|
|
|
|
|
2008-07-02 04:22:48 +00:00
|
|
|
static void
|
|
|
|
http_request_bad(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
if (req != NULL) {
|
|
|
|
fprintf(stderr, "FAILED\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_ok = 1;
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(arg, NULL);
|
2008-07-02 04:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 14:31:23 -04:00
|
|
|
http_negative_content_length_test(void *arg)
|
2008-07-02 04:22:48 +00:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2008-07-02 04:22:48 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2009-01-27 21:10:31 +00:00
|
|
|
|
2008-07-02 04:22:48 +00:00
|
|
|
test_ok = 0;
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_assert(evcon);
|
2008-07-02 04:22:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we want to schedule a request to the HTTP
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
req = evhttp_request_new(http_request_bad, data->base);
|
2008-07-02 04:22:48 +00:00
|
|
|
|
|
|
|
/* Cause the response to have a negative content-length */
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "X-Negative", "makeitso");
|
2008-07-02 04:22:48 +00:00
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
2009-01-30 17:44:13 +00:00
|
|
|
tt_abort_msg("Couldn't make request");
|
2008-07-02 04:22:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2008-07-02 04:22:48 +00:00
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
|
|
|
|
2009-11-04 20:17:32 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
http_data_length_constraints_test_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
tt_assert(req);
|
2010-11-03 15:14:29 -04:00
|
|
|
tt_int_op(evhttp_request_get_response_code(req), ==, HTTP_BADREQUEST);
|
2009-11-04 20:17:32 +00:00
|
|
|
end:
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(arg, NULL);
|
2009-11-04 20:17:32 +00:00
|
|
|
}
|
2010-12-07 11:43:52 -05:00
|
|
|
static void
|
|
|
|
http_large_entity_test_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
tt_assert(req);
|
|
|
|
tt_int_op(evhttp_request_get_response_code(req), ==, HTTP_ENTITYTOOLARGE);
|
|
|
|
end:
|
|
|
|
event_base_loopexit(arg, NULL);
|
|
|
|
}
|
2016-03-11 19:25:11 +03:00
|
|
|
static void
|
|
|
|
http_expectation_failed_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
tt_assert(req);
|
|
|
|
tt_int_op(evhttp_request_get_response_code(req), ==, HTTP_EXPECTATIONFAILED);
|
|
|
|
end:
|
|
|
|
event_base_loopexit(arg, NULL);
|
|
|
|
}
|
2010-12-07 11:43:52 -05:00
|
|
|
|
2009-11-04 20:17:32 +00:00
|
|
|
static void
|
2016-03-11 19:25:11 +03:00
|
|
|
http_data_length_constraints_test_impl(void *arg, int read_on_write_error)
|
2009-11-04 20:17:32 +00:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2009-11-04 20:17:32 +00:00
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2016-03-10 18:40:34 +03:00
|
|
|
char *long_str = NULL;
|
2016-03-11 14:23:03 +03:00
|
|
|
const size_t continue_size = 1<<20;
|
|
|
|
const size_t size = (1<<20) * 3;
|
2016-03-11 19:25:11 +03:00
|
|
|
void (*cb)(struct evhttp_request *, void *);
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2009-11-04 20:17:32 +00:00
|
|
|
|
|
|
|
test_ok = 0;
|
2016-03-11 19:25:11 +03:00
|
|
|
cb = http_failed_request_done;
|
|
|
|
if (read_on_write_error)
|
|
|
|
cb = http_data_length_constraints_test_done;
|
2009-11-04 20:17:32 +00:00
|
|
|
|
2016-03-11 14:23:03 +03:00
|
|
|
tt_assert(continue_size < size);
|
|
|
|
|
2019-01-27 15:28:28 +03:00
|
|
|
long_str = malloc(size);
|
|
|
|
memset(long_str, 'a', size);
|
|
|
|
long_str[size - 1] = '\0';
|
|
|
|
|
|
|
|
TT_BLATHER(("Creating connection to :%i", port));
|
2010-11-03 14:31:23 -04:00
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
2009-11-04 20:17:32 +00:00
|
|
|
tt_assert(evcon);
|
2016-03-11 19:25:11 +03:00
|
|
|
|
|
|
|
if (read_on_write_error)
|
|
|
|
tt_assert(!evhttp_connection_set_flags(evcon, EVHTTP_CON_READ_ON_WRITE_ERROR));
|
2009-11-04 20:17:32 +00:00
|
|
|
|
|
|
|
evhttp_connection_set_local_address(evcon, "127.0.0.1");
|
|
|
|
|
2019-01-27 15:28:28 +03:00
|
|
|
evhttp_set_max_headers_size(http, size - 1);
|
|
|
|
TT_BLATHER(("Set max header size %zu", size - 1));
|
2009-11-04 20:17:32 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
req = evhttp_request_new(http_data_length_constraints_test_done, data->base);
|
2009-11-04 20:17:32 +00:00
|
|
|
tt_assert(req);
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Longheader", long_str);
|
2019-01-27 15:28:28 +03:00
|
|
|
TT_BLATHER(("GET /?arg=val"));
|
2009-11-04 20:17:32 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/?arg=val") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2009-11-04 20:17:32 +00:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
req = evhttp_request_new(http_data_length_constraints_test_done, data->base);
|
2009-11-04 20:17:32 +00:00
|
|
|
tt_assert(req);
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
2010-02-18 17:41:15 -05:00
|
|
|
/* GET /?arg=verylongvalue HTTP/1.1 */
|
2019-01-27 15:28:28 +03:00
|
|
|
TT_BLATHER(("GET %s", long_str));
|
2009-11-04 20:17:32 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, long_str) == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2009-11-04 20:17:32 +00:00
|
|
|
|
2019-01-27 15:28:28 +03:00
|
|
|
evhttp_set_max_body_size(http, size - 2);
|
|
|
|
TT_BLATHER(("Set body header size %zu", size - 2));
|
|
|
|
|
2016-03-11 19:25:11 +03:00
|
|
|
if (read_on_write_error)
|
|
|
|
cb = http_large_entity_test_done;
|
|
|
|
req = evhttp_request_new(cb, data->base);
|
2010-11-03 15:14:29 -04:00
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
evbuffer_add_printf(evhttp_request_get_output_buffer(req), "%s", long_str);
|
2019-01-27 15:28:28 +03:00
|
|
|
TT_BLATHER(("POST /"));
|
2009-11-04 20:17:32 +00:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2009-11-04 20:17:32 +00:00
|
|
|
|
2010-12-07 11:43:52 -05:00
|
|
|
req = evhttp_request_new(http_large_entity_test_done, data->base);
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Expect", "100-continue");
|
|
|
|
evbuffer_add_printf(evhttp_request_get_output_buffer(req), "%s", long_str);
|
2019-01-27 15:28:28 +03:00
|
|
|
TT_BLATHER(("POST / (Expect: 100-continue, http_large_entity_test_done)"));
|
2010-12-07 11:43:52 -05:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
event_base_dispatch(data->base);
|
2010-12-09 11:43:12 -05:00
|
|
|
|
2019-01-27 15:28:28 +03:00
|
|
|
long_str[continue_size] = '\0';
|
|
|
|
|
2016-03-11 14:23:03 +03:00
|
|
|
req = evhttp_request_new(http_dispatcher_test_done, data->base);
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Expect", "100-continue");
|
|
|
|
evbuffer_add_printf(evhttp_request_get_output_buffer(req), "%s", long_str);
|
2019-01-27 15:28:28 +03:00
|
|
|
TT_BLATHER(("POST / (Expect: 100-continue, http_dispatcher_test_done)"));
|
2016-03-11 14:23:03 +03:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
2016-03-11 19:25:11 +03:00
|
|
|
if (read_on_write_error)
|
|
|
|
cb = http_expectation_failed_done;
|
|
|
|
req = evhttp_request_new(cb, data->base);
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Expect", "101-continue");
|
|
|
|
evbuffer_add_printf(evhttp_request_get_output_buffer(req), "%s", long_str);
|
2019-01-27 15:28:28 +03:00
|
|
|
TT_BLATHER(("POST / (Expect: 101-continue)"));
|
2016-03-11 19:25:11 +03:00
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
2010-02-18 17:41:15 -05:00
|
|
|
test_ok = 1;
|
2009-11-04 20:17:32 +00:00
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2016-03-10 18:40:34 +03:00
|
|
|
if (long_str)
|
|
|
|
free(long_str);
|
2009-11-04 20:17:32 +00:00
|
|
|
}
|
2016-03-11 19:25:11 +03:00
|
|
|
static void http_data_length_constraints_test(void *arg)
|
|
|
|
{ http_data_length_constraints_test_impl(arg, 0); }
|
|
|
|
static void http_read_on_write_error_test(void *arg)
|
|
|
|
{ http_data_length_constraints_test_impl(arg, 1); }
|
2009-11-04 20:17:32 +00:00
|
|
|
|
2016-02-15 03:13:02 +03:00
|
|
|
static void
|
2016-02-15 03:21:39 +03:00
|
|
|
http_lingering_close_test_impl(void *arg, int lingering)
|
2016-02-15 03:13:02 +03:00
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2016-03-10 18:40:34 +03:00
|
|
|
char *long_str = NULL;
|
|
|
|
size_t size = (1<<20) * 3;
|
2016-02-15 03:21:39 +03:00
|
|
|
void (*cb)(struct evhttp_request *, void *);
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2016-02-15 03:13:02 +03:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
2016-02-15 03:21:39 +03:00
|
|
|
if (lingering)
|
|
|
|
tt_assert(!evhttp_set_flags(http, EVHTTP_SERVER_LINGERING_CLOSE));
|
2016-03-10 18:40:34 +03:00
|
|
|
evhttp_set_max_body_size(http, size / 2);
|
2016-02-15 03:13:02 +03:00
|
|
|
|
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
|
|
|
tt_assert(evcon);
|
|
|
|
evhttp_connection_set_local_address(evcon, "127.0.0.1");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we want to schedule an HTTP GET request
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
2016-03-10 18:40:34 +03:00
|
|
|
long_str = malloc(size);
|
|
|
|
memset(long_str, 'a', size);
|
|
|
|
long_str[size - 1] = '\0';
|
2016-02-15 03:13:02 +03:00
|
|
|
|
2016-02-15 03:21:39 +03:00
|
|
|
if (lingering)
|
|
|
|
cb = http_large_entity_test_done;
|
|
|
|
else
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
cb = http_failed_request_done;
|
2016-02-15 03:21:39 +03:00
|
|
|
req = evhttp_request_new(cb, data->base);
|
2016-02-15 03:13:02 +03:00
|
|
|
tt_assert(req);
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
evbuffer_add_printf(evhttp_request_get_output_buffer(req), "%s", long_str);
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_POST, "/") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
test_ok = 1;
|
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
2016-03-10 18:40:34 +03:00
|
|
|
if (long_str)
|
|
|
|
free(long_str);
|
2016-02-15 03:13:02 +03:00
|
|
|
}
|
2016-02-15 03:21:39 +03:00
|
|
|
static void http_non_lingering_close_test(void *arg)
|
|
|
|
{ http_lingering_close_test_impl(arg, 0); }
|
|
|
|
static void http_lingering_close_test(void *arg)
|
|
|
|
{ http_lingering_close_test_impl(arg, 1); }
|
2016-02-15 03:13:02 +03:00
|
|
|
|
2010-02-03 14:34:56 -08:00
|
|
|
/*
|
|
|
|
* Testing client reset of server chunked connections
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct terminate_state {
|
2010-11-03 14:31:23 -04:00
|
|
|
struct event_base *base;
|
2010-02-03 14:34:56 -08:00
|
|
|
struct evhttp_request *req;
|
|
|
|
struct bufferevent *bev;
|
2010-03-05 12:47:46 -05:00
|
|
|
evutil_socket_t fd;
|
2010-02-13 17:04:17 -08:00
|
|
|
int gotclosecb: 1;
|
2015-09-08 15:44:13 +03:00
|
|
|
int oneshot: 1;
|
2010-11-03 14:31:23 -04:00
|
|
|
};
|
2010-02-03 14:34:56 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
terminate_chunked_trickle_cb(evutil_socket_t fd, short events, void *arg)
|
|
|
|
{
|
|
|
|
struct terminate_state *state = arg;
|
2010-03-13 00:55:39 -05:00
|
|
|
struct evbuffer *evb;
|
2015-09-08 15:44:13 +03:00
|
|
|
|
|
|
|
if (!state->req) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-03 14:34:56 -08:00
|
|
|
|
|
|
|
if (evhttp_request_get_connection(state->req) == NULL) {
|
|
|
|
test_ok = 1;
|
|
|
|
evhttp_request_free(state->req);
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_loopexit(state->base,NULL);
|
2010-02-13 16:59:37 -08:00
|
|
|
return;
|
2010-02-03 14:34:56 -08:00
|
|
|
}
|
|
|
|
|
2010-03-13 00:55:39 -05:00
|
|
|
evb = evbuffer_new();
|
2010-02-03 14:34:56 -08:00
|
|
|
evbuffer_add_printf(evb, "%p", evb);
|
|
|
|
evhttp_send_reply_chunk(state->req, evb);
|
|
|
|
evbuffer_free(evb);
|
|
|
|
|
2015-09-08 15:44:13 +03:00
|
|
|
if (!state->oneshot) {
|
|
|
|
struct timeval tv;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 3000;
|
|
|
|
EVUTIL_ASSERT(state);
|
|
|
|
EVUTIL_ASSERT(state->base);
|
|
|
|
event_base_once(state->base, -1, EV_TIMEOUT, terminate_chunked_trickle_cb, arg, &tv);
|
|
|
|
}
|
2010-02-03 14:34:56 -08:00
|
|
|
}
|
|
|
|
|
2010-02-13 17:04:17 -08:00
|
|
|
static void
|
|
|
|
terminate_chunked_close_cb(struct evhttp_connection *evcon, void *arg)
|
|
|
|
{
|
|
|
|
struct terminate_state *state = arg;
|
|
|
|
state->gotclosecb = 1;
|
2015-09-08 15:44:13 +03:00
|
|
|
|
|
|
|
/** TODO: though we can do this unconditionally */
|
|
|
|
if (state->oneshot) {
|
|
|
|
evhttp_request_free(state->req);
|
|
|
|
state->req = NULL;
|
|
|
|
event_base_loopexit(state->base,NULL);
|
|
|
|
}
|
2010-02-13 17:04:17 -08:00
|
|
|
}
|
|
|
|
|
2010-02-03 14:34:56 -08:00
|
|
|
static void
|
|
|
|
terminate_chunked_cb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct terminate_state *state = arg;
|
|
|
|
struct timeval tv;
|
|
|
|
|
2010-02-13 17:04:17 -08:00
|
|
|
/* we want to know if this connection closes on us */
|
|
|
|
evhttp_connection_set_closecb(
|
|
|
|
evhttp_request_get_connection(req),
|
|
|
|
terminate_chunked_close_cb, arg);
|
2010-02-18 17:41:15 -05:00
|
|
|
|
2010-02-03 14:34:56 -08:00
|
|
|
state->req = req;
|
|
|
|
|
|
|
|
evhttp_send_reply_start(req, HTTP_OK, "OK");
|
|
|
|
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 3000;
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_once(state->base, -1, EV_TIMEOUT, terminate_chunked_trickle_cb, arg, &tv);
|
2010-02-03 14:34:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-05 12:47:46 -05:00
|
|
|
terminate_chunked_client(evutil_socket_t fd, short event, void *arg)
|
2010-02-03 14:34:56 -08:00
|
|
|
{
|
|
|
|
struct terminate_state *state = arg;
|
|
|
|
bufferevent_free(state->bev);
|
2010-04-14 15:42:57 -04:00
|
|
|
evutil_closesocket(state->fd);
|
2010-02-03 14:34:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
terminate_readcb(struct bufferevent *bev, void *arg)
|
|
|
|
{
|
|
|
|
/* just drop the data */
|
|
|
|
evbuffer_drain(bufferevent_get_input(bev), -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2015-09-08 15:44:13 +03:00
|
|
|
http_terminate_chunked_test_impl(void *arg, int oneshot)
|
2010-02-03 14:34:56 -08:00
|
|
|
{
|
2010-11-03 14:31:23 -04:00
|
|
|
struct basic_test_data *data = arg;
|
2010-02-03 14:34:56 -08:00
|
|
|
struct bufferevent *bev = NULL;
|
|
|
|
struct timeval tv;
|
|
|
|
const char *http_request;
|
2010-09-03 18:48:31 -04:00
|
|
|
ev_uint16_t port = 0;
|
2019-01-29 21:12:33 +03:00
|
|
|
evutil_socket_t fd = EVUTIL_INVALID_SOCKET;
|
2010-11-03 14:31:23 -04:00
|
|
|
struct terminate_state terminate_state;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2010-02-03 14:34:56 -08:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
evhttp_del_cb(http, "/test");
|
|
|
|
tt_assert(evhttp_set_cb(http, "/test",
|
|
|
|
terminate_chunked_cb, &terminate_state) == 0);
|
|
|
|
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2010-02-03 14:34:56 -08:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2010-11-03 14:31:23 -04:00
|
|
|
bev = bufferevent_socket_new(data->base, fd, 0);
|
2010-10-21 12:48:13 -04:00
|
|
|
bufferevent_setcb(bev, terminate_readcb, http_writecb,
|
2010-11-03 14:31:23 -04:00
|
|
|
http_errorcb, data->base);
|
2010-02-03 14:34:56 -08:00
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
memset(&terminate_state, 0, sizeof(terminate_state));
|
|
|
|
terminate_state.base = data->base;
|
2010-02-03 14:34:56 -08:00
|
|
|
terminate_state.fd = fd;
|
|
|
|
terminate_state.bev = bev;
|
2010-02-13 17:04:17 -08:00
|
|
|
terminate_state.gotclosecb = 0;
|
2015-09-08 15:44:13 +03:00
|
|
|
terminate_state.oneshot = oneshot;
|
2010-02-03 14:34:56 -08:00
|
|
|
|
|
|
|
/* first half of the http request */
|
|
|
|
http_request =
|
|
|
|
"GET /test HTTP/1.1\r\n"
|
|
|
|
"Host: some\r\n\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
evutil_timerclear(&tv);
|
|
|
|
tv.tv_usec = 10000;
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_once(data->base, -1, EV_TIMEOUT, terminate_chunked_client, &terminate_state,
|
2010-02-03 14:34:56 -08:00
|
|
|
&tv);
|
|
|
|
|
2010-11-03 14:31:23 -04:00
|
|
|
event_base_dispatch(data->base);
|
2010-02-03 14:34:56 -08:00
|
|
|
|
2010-02-13 17:04:17 -08:00
|
|
|
if (terminate_state.gotclosecb == 0)
|
|
|
|
test_ok = 0;
|
|
|
|
|
2010-02-03 14:34:56 -08:00
|
|
|
end:
|
|
|
|
if (fd >= 0)
|
2010-04-14 15:42:57 -04:00
|
|
|
evutil_closesocket(fd);
|
2010-02-03 14:34:56 -08:00
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
2015-09-08 15:44:13 +03:00
|
|
|
static void
|
|
|
|
http_terminate_chunked_test(void *arg)
|
|
|
|
{
|
|
|
|
http_terminate_chunked_test_impl(arg, 0);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
http_terminate_chunked_oneshot_test(void *arg)
|
|
|
|
{
|
|
|
|
http_terminate_chunked_test_impl(arg, 1);
|
|
|
|
}
|
2010-02-03 14:34:56 -08:00
|
|
|
|
2013-01-27 02:17:02 +04:00
|
|
|
static struct regress_dns_server_table ipv6_search_table[] = {
|
2015-10-09 01:50:05 +03:00
|
|
|
{ "localhost", "AAAA", "::1", 0, 0 },
|
|
|
|
{ NULL, NULL, NULL, 0, 0 }
|
2013-01-27 02:17:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2014-03-27 00:49:00 +04:00
|
|
|
http_ipv6_for_domain_test_impl(void *arg, int family)
|
2013-01-27 02:17:02 +04:00
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
struct evdns_base *dns_base = NULL;
|
|
|
|
ev_uint16_t portnum = 0;
|
|
|
|
char address[64];
|
|
|
|
|
2020-05-21 12:46:20 +03:00
|
|
|
tt_assert(regress_dnsserver(data->base, &portnum, ipv6_search_table, NULL));
|
2013-01-27 02:17:02 +04:00
|
|
|
|
|
|
|
dns_base = evdns_base_new(data->base, 0/* init name servers */);
|
|
|
|
tt_assert(dns_base);
|
|
|
|
|
|
|
|
/* Add ourself as the only nameserver, and make sure we really are
|
|
|
|
* the only nameserver. */
|
|
|
|
evutil_snprintf(address, sizeof(address), "127.0.0.1:%d", portnum);
|
|
|
|
evdns_base_nameserver_ip_add(dns_base, address);
|
|
|
|
|
2014-03-27 00:44:51 +04:00
|
|
|
http_connection_test_(arg, 0 /* not persistent */, "localhost", dns_base,
|
2016-11-19 15:54:52 +03:00
|
|
|
1 /* ipv6 */, family, 0);
|
2013-01-27 02:17:02 +04:00
|
|
|
|
|
|
|
end:
|
|
|
|
if (dns_base)
|
|
|
|
evdns_base_free(dns_base, 0);
|
|
|
|
regress_clean_dnsserver();
|
|
|
|
}
|
2014-03-27 00:49:00 +04:00
|
|
|
static void
|
|
|
|
http_ipv6_for_domain_test(void *arg)
|
|
|
|
{
|
|
|
|
http_ipv6_for_domain_test_impl(arg, AF_UNSPEC);
|
|
|
|
}
|
2013-01-27 02:17:02 +04:00
|
|
|
|
2013-10-01 19:54:09 +04:00
|
|
|
static void
|
|
|
|
http_request_get_addr_on_close(struct evhttp_connection *evcon, void *arg)
|
|
|
|
{
|
|
|
|
const struct sockaddr *storage;
|
|
|
|
char addrbuf[128];
|
|
|
|
char local[] = "127.0.0.1:";
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
tt_assert(evcon);
|
|
|
|
|
|
|
|
storage = evhttp_connection_get_addr(evcon);
|
|
|
|
tt_assert(storage);
|
|
|
|
|
|
|
|
evutil_format_sockaddr_port_((struct sockaddr *)storage, addrbuf, sizeof(addrbuf));
|
|
|
|
tt_assert(!strncmp(addrbuf, local, sizeof(local) - 1));
|
|
|
|
|
|
|
|
test_ok = 1;
|
|
|
|
return;
|
|
|
|
|
|
|
|
end:
|
|
|
|
test_ok = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_get_addr_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2013-10-01 19:54:09 +04:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
exit_base = data->base;
|
|
|
|
|
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
|
|
|
tt_assert(evcon);
|
|
|
|
evhttp_connection_set_closecb(evcon, http_request_get_addr_on_close, arg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we want to schedule a request to the HTTP
|
|
|
|
* server using our make request method.
|
|
|
|
*/
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_done, (void *)BASIC_REQUEST_BODY);
|
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
http_request_get_addr_on_close(evcon, NULL);
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
|
|
|
|
2014-03-27 00:40:14 +04:00
|
|
|
static void
|
|
|
|
http_set_family_test(void *arg)
|
|
|
|
{
|
2016-11-19 15:54:52 +03:00
|
|
|
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_UNSPEC, 0);
|
2014-03-27 00:40:14 +04:00
|
|
|
}
|
|
|
|
static void
|
|
|
|
http_set_family_ipv4_test(void *arg)
|
|
|
|
{
|
2016-11-19 15:54:52 +03:00
|
|
|
http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_INET, 0);
|
2014-03-27 00:40:14 +04:00
|
|
|
}
|
2014-03-27 00:49:00 +04:00
|
|
|
static void
|
|
|
|
http_set_family_ipv6_test(void *arg)
|
|
|
|
{
|
|
|
|
http_ipv6_for_domain_test_impl(arg, AF_INET6);
|
|
|
|
}
|
2014-03-27 00:40:14 +04:00
|
|
|
|
2015-09-09 17:45:44 +03:00
|
|
|
static void
|
|
|
|
http_write_during_read(evutil_socket_t fd, short what, void *arg)
|
|
|
|
{
|
|
|
|
struct bufferevent *bev = arg;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
bufferevent_write(bev, "foobar", strlen("foobar"));
|
|
|
|
|
|
|
|
evutil_timerclear(&tv);
|
|
|
|
tv.tv_sec = 1;
|
|
|
|
event_base_loopexit(exit_base, &tv);
|
|
|
|
}
|
|
|
|
static void
|
2015-11-15 00:12:25 +03:00
|
|
|
http_write_during_read_test_impl(void *arg, int ssl)
|
2015-09-09 17:45:44 +03:00
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct bufferevent *bev = NULL;
|
|
|
|
struct timeval tv;
|
2019-01-29 21:12:33 +03:00
|
|
|
evutil_socket_t fd;
|
2015-09-09 17:45:44 +03:00
|
|
|
const char *http_request;
|
2020-09-06 15:33:32 +08:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, ssl);
|
2015-09-09 17:45:44 +03:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
exit_base = data->base;
|
|
|
|
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2020-09-06 15:33:32 +08:00
|
|
|
bev = create_bev(data->base, fd, ssl, 0);
|
2015-09-09 17:45:44 +03:00
|
|
|
bufferevent_setcb(bev, NULL, NULL, NULL, data->base);
|
|
|
|
bufferevent_disable(bev, EV_READ);
|
|
|
|
|
|
|
|
http_request =
|
|
|
|
"GET /large HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
bufferevent_write(bev, http_request, strlen(http_request));
|
|
|
|
evutil_timerclear(&tv);
|
|
|
|
tv.tv_usec = 10000;
|
|
|
|
event_base_once(data->base, -1, EV_TIMEOUT, http_write_during_read, bev, &tv);
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
2019-01-29 21:12:33 +03:00
|
|
|
end:
|
2015-09-09 17:45:44 +03:00
|
|
|
if (bev)
|
|
|
|
bufferevent_free(bev);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
2015-11-15 00:12:25 +03:00
|
|
|
static void http_write_during_read_test(void *arg)
|
2017-03-14 13:21:16 +03:00
|
|
|
{ http_write_during_read_test_impl(arg, 0); }
|
2015-09-09 17:45:44 +03:00
|
|
|
|
2015-09-09 19:15:18 +03:00
|
|
|
static void
|
|
|
|
http_request_own_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
2016-03-25 11:04:51 +03:00
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
2015-09-09 19:15:18 +03:00
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
exit_base = data->base;
|
|
|
|
|
|
|
|
evhttp_free(http);
|
|
|
|
|
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
|
|
|
tt_assert(evcon);
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_no_action_done, NULL);
|
|
|
|
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
evhttp_request_own(req);
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (req)
|
|
|
|
evhttp_request_free(req);
|
|
|
|
|
|
|
|
test_ok = 1;
|
|
|
|
}
|
|
|
|
|
2017-11-04 19:13:28 +03:00
|
|
|
static void http_run_bev_request(struct event_base *base, int port,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct bufferevent *bev = NULL;
|
|
|
|
va_list ap;
|
|
|
|
evutil_socket_t fd;
|
|
|
|
struct evbuffer *out;
|
|
|
|
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2019-01-29 21:12:33 +03:00
|
|
|
tt_assert(fd != EVUTIL_INVALID_SOCKET);
|
2017-11-04 19:13:28 +03:00
|
|
|
|
|
|
|
/* Stupid thing to send a request */
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(base, fd, 0, 0);
|
2017-11-04 19:13:28 +03:00
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb,
|
|
|
|
http_errorcb, base);
|
|
|
|
out = bufferevent_get_output(bev);
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
evbuffer_add_vprintf(out, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
event_base_dispatch(base);
|
|
|
|
|
2019-01-29 21:12:33 +03:00
|
|
|
end:
|
|
|
|
if (bev)
|
|
|
|
bufferevent_free(bev);
|
2017-11-04 19:13:28 +03:00
|
|
|
}
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
static void
|
|
|
|
http_request_extra_body_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
struct bufferevent *bev = NULL;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
int i;
|
2017-11-04 19:13:28 +03:00
|
|
|
struct evhttp *http =
|
|
|
|
http_setup_gencb(&port, data->base, 0, http_timeout_cb, NULL);
|
|
|
|
struct evbuffer *body = NULL;
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
|
|
|
|
exit_base = data->base;
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
body = evbuffer_new();
|
|
|
|
for (i = 0; i < 10000; ++i)
|
|
|
|
evbuffer_add_printf(body, "this is the body that HEAD should not have");
|
|
|
|
|
2017-11-04 19:13:28 +03:00
|
|
|
http_run_bev_request(data->base, port,
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
"HEAD /timeout HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"Content-Length: %i\r\n"
|
2017-11-04 19:13:28 +03:00
|
|
|
"\r\n%s",
|
|
|
|
(int)evbuffer_get_length(body),
|
|
|
|
evbuffer_pullup(body, -1)
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
);
|
2017-11-04 19:13:28 +03:00
|
|
|
tt_assert(test_ok == -2);
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
|
2017-11-04 19:13:28 +03:00
|
|
|
http_run_bev_request(data->base, port,
|
|
|
|
"HEAD /__gencb__ HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Connection: close\r\n"
|
|
|
|
"Content-Length: %i\r\n"
|
|
|
|
"\r\n%s",
|
|
|
|
(int)evbuffer_get_length(body),
|
|
|
|
evbuffer_pullup(body, -1)
|
|
|
|
);
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
tt_assert(test_ok == -2);
|
|
|
|
|
|
|
|
end:
|
|
|
|
evhttp_free(http);
|
|
|
|
if (bev)
|
|
|
|
bufferevent_free(bev);
|
|
|
|
if (body)
|
|
|
|
evbuffer_free(body);
|
|
|
|
}
|
|
|
|
|
2017-12-01 01:29:32 +00:00
|
|
|
struct http_newreqcb_test_state
|
|
|
|
{
|
|
|
|
int connections_started;
|
|
|
|
int connections_noticed;
|
|
|
|
int connections_throttled;
|
|
|
|
int connections_good;
|
|
|
|
int connections_error;
|
|
|
|
int connections_done;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_newreqcb_test_state_check(struct http_newreqcb_test_state* state)
|
|
|
|
{
|
|
|
|
tt_int_op(state->connections_started, >=, 0);
|
|
|
|
tt_int_op(state->connections_started, >=, state->connections_noticed);
|
|
|
|
tt_int_op(state->connections_throttled, >=, state->connections_error);
|
|
|
|
|
|
|
|
tt_int_op(state->connections_done, <=, state->connections_started);
|
|
|
|
if (state->connections_good + state->connections_error == state->connections_started) {
|
|
|
|
tt_int_op(state->connections_throttled, ==, state->connections_error);
|
|
|
|
tt_int_op(state->connections_good + state->connections_error, ==, state->connections_done);
|
|
|
|
event_base_loopexit(exit_base, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
end:
|
|
|
|
tt_fail();
|
|
|
|
exit(17);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_request_done_newreqcb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct http_newreqcb_test_state* state = arg;
|
|
|
|
if (req && evhttp_request_get_response_code(req) == HTTP_OK) {
|
|
|
|
++state->connections_good;
|
|
|
|
evhttp_request_set_error_cb(req, NULL);
|
|
|
|
}
|
|
|
|
++state->connections_done;
|
|
|
|
|
|
|
|
http_newreqcb_test_state_check(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_request_error_newreqcb(enum evhttp_request_error err, void *arg)
|
|
|
|
{
|
|
|
|
struct http_newreqcb_test_state* state = arg;
|
|
|
|
++state->connections_error;
|
|
|
|
|
|
|
|
http_newreqcb_test_state_check(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
http_newreqcb(struct evhttp_request* req, void *arg)
|
|
|
|
{
|
|
|
|
struct http_newreqcb_test_state* state = arg;
|
|
|
|
++state->connections_noticed;
|
|
|
|
http_newreqcb_test_state_check(state);
|
|
|
|
if (1 == state->connections_noticed % 7) {
|
|
|
|
state->connections_throttled++;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_newreqcb_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
|
|
|
struct evhttp_connection *evcons[100];
|
|
|
|
struct http_newreqcb_test_state newreqcb_test_state;
|
|
|
|
unsigned n;
|
|
|
|
|
|
|
|
exit_base = data->base;
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
memset(&newreqcb_test_state, 0, sizeof(newreqcb_test_state));
|
|
|
|
memset(evcons, 0, sizeof(evcons));
|
|
|
|
|
|
|
|
evhttp_set_newreqcb(http, http_newreqcb, &newreqcb_test_state);
|
|
|
|
|
|
|
|
for (n = 0; n < sizeof(evcons)/sizeof(evcons[0]); ++n) {
|
|
|
|
struct evhttp_connection* evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
|
|
|
evcons[n] = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
|
|
|
evcon = evcons[n];
|
|
|
|
evhttp_connection_set_retries(evcon, 0);
|
|
|
|
|
|
|
|
tt_assert(evcon);
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_done_newreqcb, &newreqcb_test_state);
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Connection", "close");
|
|
|
|
evhttp_request_set_error_cb(req, http_request_error_newreqcb);
|
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
|
|
|
|
++newreqcb_test_state.connections_started;
|
|
|
|
http_newreqcb_test_state_check(&newreqcb_test_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
http_newreqcb_test_state_check(&newreqcb_test_state);
|
|
|
|
tt_int_op(newreqcb_test_state.connections_throttled, >, 0);
|
|
|
|
|
|
|
|
end:
|
|
|
|
evhttp_free(http);
|
|
|
|
|
|
|
|
for (n = 0; n < sizeof(evcons)/sizeof(evcons[0]); ++n) {
|
|
|
|
if (evcons[n])
|
|
|
|
evhttp_connection_free(evcons[n]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-04 06:53:42 +03:00
|
|
|
static void
|
|
|
|
http_timeout_read_client_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
|
|
|
struct timeval tv;
|
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
exit_base = data->base;
|
|
|
|
|
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
|
|
|
tt_assert(evcon);
|
|
|
|
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 100000;
|
|
|
|
evhttp_connection_set_connect_timeout_tv(evcon, &tv);
|
|
|
|
evhttp_connection_set_write_timeout_tv(evcon, &tv);
|
|
|
|
tv.tv_usec = 500000;
|
|
|
|
evhttp_connection_set_read_timeout_tv(evcon, &tv);
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_done, (void*)"");
|
|
|
|
tt_assert(req);
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Host", "somehost");
|
|
|
|
tt_int_op(evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/delay"), ==, 0);
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
tt_int_op(test_ok, ==, 1);
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
|
|
|
|
2016-02-09 18:01:00 +00:00
|
|
|
/*
|
|
|
|
* Error callback tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ERRCBFLAG_GENCB (0x01)
|
|
|
|
#define ERRCBFLAG_ERRCB (0x02)
|
|
|
|
#define ERRCBFLAG_BOTHCB (ERRCBFLAG_GENCB | ERRCBFLAG_ERRCB)
|
|
|
|
|
|
|
|
struct error_callback_test {
|
|
|
|
unsigned char flags;
|
|
|
|
enum evhttp_cmd_type type;
|
|
|
|
int response_code;
|
|
|
|
int length;
|
|
|
|
} error_callback_tests[] = {
|
|
|
|
{0 , EVHTTP_REQ_GET , HTTP_NOTFOUND , 152} , /* 0 */
|
|
|
|
{0 , EVHTTP_REQ_POST , HTTP_NOTIMPLEMENTED , 101} , /* 1 */
|
|
|
|
{ERRCBFLAG_GENCB , EVHTTP_REQ_GET , HTTP_NOTFOUND , 89} , /* 2 */
|
|
|
|
{ERRCBFLAG_GENCB , EVHTTP_REQ_POST , HTTP_NOTIMPLEMENTED , 101} , /* 3 */
|
|
|
|
{ERRCBFLAG_ERRCB , EVHTTP_REQ_GET , HTTP_NOTFOUND , 3} , /* 4 */
|
|
|
|
{ERRCBFLAG_ERRCB , EVHTTP_REQ_POST , HTTP_NOTIMPLEMENTED , 101} , /* 5 */
|
|
|
|
{ERRCBFLAG_BOTHCB , EVHTTP_REQ_GET , HTTP_NOTFOUND , 3} , /* 6 */
|
|
|
|
{ERRCBFLAG_BOTHCB , EVHTTP_REQ_POST , HTTP_NOTIMPLEMENTED , 3} , /* 7 */
|
|
|
|
{ERRCBFLAG_ERRCB , EVHTTP_REQ_GET , HTTP_NOTFOUND , 0} , /* 8 */
|
|
|
|
{ERRCBFLAG_ERRCB , EVHTTP_REQ_GET , HTTP_NOTFOUND , 152} , /* 9 */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct error_callback_state
|
|
|
|
{
|
|
|
|
struct basic_test_data *data;
|
|
|
|
unsigned test_index;
|
|
|
|
struct error_callback_test *test;
|
|
|
|
int test_failed;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_error_callback_gencb(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct error_callback_state *state_info = arg;
|
|
|
|
|
|
|
|
switch (state_info->test_index) {
|
|
|
|
case 2:
|
|
|
|
case 6:
|
|
|
|
evhttp_send_error(req, HTTP_NOTFOUND, NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
evhttp_send_error(req, HTTP_INTERNAL, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
http_error_callback_errorcb(struct evhttp_request *req, struct evbuffer *buf,
|
|
|
|
int error, const char *reason, void *arg)
|
|
|
|
{
|
|
|
|
struct error_callback_state *state_info = arg;
|
|
|
|
int return_code = -1;
|
|
|
|
|
|
|
|
switch (state_info->test_index) {
|
|
|
|
case 4:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
evbuffer_add_printf(buf, "%d", error);
|
|
|
|
return_code = 0;
|
|
|
|
break;
|
|
|
|
case 8: /* Add nothing to buffer and then return 0 to trigger default */
|
|
|
|
return_code = 0;
|
|
|
|
break;
|
|
|
|
case 9: /* Add text to buffer but then return -1 to trigger default */
|
|
|
|
evbuffer_add_printf(buf, "%d", error);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_error_callback_test_done(struct evhttp_request *req, void *arg)
|
|
|
|
{
|
|
|
|
struct evkeyvalq *headers;
|
|
|
|
const char *header_text;
|
|
|
|
struct error_callback_state *state_info = arg;
|
|
|
|
struct error_callback_test *test_info;
|
|
|
|
|
|
|
|
test_info = state_info->test;
|
|
|
|
|
|
|
|
tt_assert(req);
|
2020-08-29 18:41:39 +02:00
|
|
|
tt_assert_op_type(evhttp_request_get_command(req), ==,
|
|
|
|
test_info->type, enum evhttp_cmd_type, "%d");
|
2016-02-09 18:01:00 +00:00
|
|
|
tt_int_op(evhttp_request_get_response_code(req), ==,
|
|
|
|
test_info->response_code);
|
|
|
|
|
|
|
|
headers = evhttp_request_get_input_headers(req);
|
|
|
|
tt_assert(headers);
|
|
|
|
header_text = evhttp_find_header(headers, "Content-Type");
|
|
|
|
tt_assert_msg(header_text, "Missing Content-Type");
|
|
|
|
tt_str_op(header_text, ==, "text/html");
|
|
|
|
tt_int_op(evbuffer_get_length(evhttp_request_get_input_buffer(req)),
|
|
|
|
==, test_info->length);
|
|
|
|
|
|
|
|
event_base_loopexit(state_info->data->base, NULL);
|
|
|
|
return;
|
|
|
|
|
|
|
|
end:
|
|
|
|
state_info->test_failed = 1;
|
|
|
|
event_base_loopexit(state_info->data->base, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
http_error_callback_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
struct evhttp *http = NULL;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp_connection *evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
|
|
|
struct error_callback_state state_info;
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
http = http_setup(&port, data->base, 0);
|
|
|
|
evhttp_set_allowed_methods(http,
|
|
|
|
EVHTTP_REQ_GET |
|
|
|
|
EVHTTP_REQ_HEAD |
|
|
|
|
EVHTTP_REQ_PUT |
|
|
|
|
EVHTTP_REQ_DELETE);
|
|
|
|
|
|
|
|
evcon = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
|
|
|
tt_assert(evcon);
|
|
|
|
|
|
|
|
/* also bind to local host */
|
|
|
|
evhttp_connection_set_local_address(evcon, "127.0.0.1");
|
|
|
|
|
|
|
|
/* Initialise the state info */
|
|
|
|
state_info.data = data;
|
|
|
|
state_info.test = error_callback_tests;
|
|
|
|
state_info.test_failed = 0;
|
|
|
|
|
|
|
|
/* Perform all the tests */
|
|
|
|
for (state_info.test_index = 0;
|
|
|
|
(state_info.test_index < ARRAY_SIZE(error_callback_tests)) &&
|
|
|
|
(!state_info.test_failed);
|
|
|
|
state_info.test_index++)
|
|
|
|
{
|
|
|
|
evhttp_set_gencb(http,
|
|
|
|
((state_info.test->flags & ERRCBFLAG_GENCB) != 0 ?
|
|
|
|
http_error_callback_gencb : NULL),
|
|
|
|
&state_info);
|
|
|
|
evhttp_set_errorcb(http,
|
|
|
|
((state_info.test->flags & ERRCBFLAG_ERRCB) != 0 ?
|
|
|
|
http_error_callback_errorcb : NULL),
|
|
|
|
&state_info);
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_error_callback_test_done,
|
|
|
|
&state_info);
|
|
|
|
tt_assert(req);
|
|
|
|
if (evhttp_make_request(evcon, req, state_info.test->type,
|
|
|
|
"/missing") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
if (!state_info.test_failed)
|
|
|
|
test_ok++;
|
|
|
|
else
|
|
|
|
tt_abort_printf(("Sub-test %d failed",
|
|
|
|
state_info.test_index));
|
|
|
|
state_info.test++;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (evcon)
|
|
|
|
evhttp_connection_free(evcon);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
|
|
|
|
2019-03-04 06:53:42 +03:00
|
|
|
static void http_add_output_buffer(int fd, short events, void *arg)
|
|
|
|
{
|
|
|
|
evbuffer_add(arg, POST_DATA, strlen(POST_DATA));
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
http_timeout_read_server_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
struct timeval tv;
|
|
|
|
struct bufferevent *bev;
|
|
|
|
struct evbuffer *out;
|
|
|
|
int fd = -1;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
|
|
|
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 100000;
|
|
|
|
evhttp_set_write_timeout_tv(http, &tv);
|
|
|
|
tv.tv_usec = 500000;
|
|
|
|
evhttp_set_read_timeout_tv(http, &tv);
|
|
|
|
|
|
|
|
fd = http_connect("127.0.0.1", port);
|
2020-06-25 21:56:31 +03:00
|
|
|
bev = create_bev(data->base, fd, 0, 0);
|
2019-03-04 06:53:42 +03:00
|
|
|
bufferevent_setcb(bev, http_readcb, http_writecb, http_errorcb, data->base);
|
|
|
|
out = bufferevent_get_output(bev);
|
|
|
|
|
|
|
|
evbuffer_add_printf(out,
|
|
|
|
"POST /postit HTTP/1.1\r\n"
|
|
|
|
"Host: somehost\r\n"
|
|
|
|
"Content-Length: " EV_SIZE_FMT "\r\n"
|
|
|
|
"\r\n", strlen(POST_DATA));
|
|
|
|
|
|
|
|
tv.tv_usec = 200000;
|
|
|
|
event_base_once(data->base, -1, EV_TIMEOUT, http_add_output_buffer, out, &tv);
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
tt_int_op(test_ok, ==, 3);
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (bev)
|
|
|
|
bufferevent_free(bev);
|
|
|
|
if (fd != -1)
|
|
|
|
evutil_closesocket(fd);
|
|
|
|
if (http)
|
|
|
|
evhttp_free(http);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-01 01:29:32 +00:00
|
|
|
|
2020-05-25 03:34:16 +03:00
|
|
|
static void
|
|
|
|
http_max_connections_test(void *arg)
|
|
|
|
{
|
|
|
|
struct basic_test_data *data = arg;
|
|
|
|
ev_uint16_t port = 0;
|
|
|
|
struct evhttp *http = http_setup(&port, data->base, 0);
|
|
|
|
struct evhttp_connection *evcons[2];
|
|
|
|
struct http_newreqcb_test_state newreqcb_test_state;
|
|
|
|
unsigned n;
|
|
|
|
|
|
|
|
exit_base = data->base;
|
|
|
|
test_ok = 0;
|
|
|
|
|
|
|
|
memset(&newreqcb_test_state, 0, sizeof(newreqcb_test_state));
|
|
|
|
memset(evcons, 0, sizeof(evcons));
|
|
|
|
|
|
|
|
evhttp_set_max_connections(http, ARRAY_SIZE(evcons)-1);
|
|
|
|
|
|
|
|
for (n = 0; n < sizeof(evcons)/sizeof(evcons[0]); ++n) {
|
|
|
|
struct evhttp_connection* evcon = NULL;
|
|
|
|
struct evhttp_request *req = NULL;
|
|
|
|
evcons[n] = evhttp_connection_base_new(data->base, NULL, "127.0.0.1", port);
|
|
|
|
evcon = evcons[n];
|
|
|
|
evhttp_connection_set_retries(evcon, 0);
|
|
|
|
|
|
|
|
tt_assert(evcon);
|
|
|
|
|
|
|
|
req = evhttp_request_new(http_request_done_newreqcb, &newreqcb_test_state);
|
|
|
|
evhttp_add_header(evhttp_request_get_output_headers(req), "Connection", "close");
|
|
|
|
evhttp_request_set_error_cb(req, http_request_error_newreqcb);
|
|
|
|
|
|
|
|
/* We give ownership of the request to the connection */
|
|
|
|
if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
|
|
|
|
tt_abort_msg("Couldn't make request");
|
|
|
|
}
|
|
|
|
|
|
|
|
++newreqcb_test_state.connections_started;
|
|
|
|
http_newreqcb_test_state_check(&newreqcb_test_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: http_newreqcb_test_state_check will not stop the base, since:
|
|
|
|
* - connections_done == 2
|
|
|
|
* - connections_good == 1
|
|
|
|
*
|
|
|
|
* hence timeout
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct timeval tv = { 0, 300e3 };
|
|
|
|
event_base_loopexit(data->base, &tv);
|
|
|
|
}
|
|
|
|
|
|
|
|
event_base_dispatch(data->base);
|
|
|
|
|
|
|
|
http_newreqcb_test_state_check(&newreqcb_test_state);
|
|
|
|
tt_int_op(newreqcb_test_state.connections_error, ==, 0);
|
|
|
|
tt_int_op(newreqcb_test_state.connections_done, ==, 2);
|
|
|
|
tt_int_op(newreqcb_test_state.connections_good, ==, 1);
|
|
|
|
|
|
|
|
end:
|
|
|
|
evhttp_free(http);
|
|
|
|
|
|
|
|
for (n = 0; n < ARRAY_SIZE(evcons); ++n) {
|
|
|
|
if (evcons[n]) {
|
|
|
|
evhttp_connection_free(evcons[n]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
#define HTTP_LEGACY(name) \
|
2009-04-21 18:46:30 +00:00
|
|
|
{ #name, run_legacy_test_fn, TT_ISOLATED|TT_LEGACY, &legacy_setup, \
|
2010-02-18 17:41:15 -05:00
|
|
|
http_##name##_test }
|
2009-01-30 17:44:13 +00:00
|
|
|
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
#define HTTP_CAST_ARG(a) ((void *)(a))
|
2017-01-07 11:48:28 +03:00
|
|
|
#define HTTP_OFF_N(title, name, arg) \
|
|
|
|
{ #title, http_##name##_test, TT_ISOLATED|TT_OFF_BY_DEFAULT, &basic_setup, HTTP_CAST_ARG(arg) }
|
2019-04-03 07:26:21 +03:00
|
|
|
#define HTTP_RET_N(title, name, test_opts, arg) \
|
|
|
|
{ #title, http_##name##_test, TT_ISOLATED|TT_RETRIABLE|test_opts, &basic_setup, HTTP_CAST_ARG(arg) }
|
|
|
|
#define HTTP_N(title, name, test_opts, arg) \
|
|
|
|
{ #title, http_##name##_test, TT_ISOLATED|test_opts, &basic_setup, HTTP_CAST_ARG(arg) }
|
|
|
|
#define HTTP(name) HTTP_N(name, name, 0, NULL)
|
2021-09-19 10:54:27 +03:00
|
|
|
#define HTTP_OPT(name, opt) HTTP_N(name, name, opt, NULL)
|
2015-11-05 10:58:41 +03:00
|
|
|
#define HTTPS(name) \
|
2020-09-06 15:33:32 +08:00
|
|
|
{ "https_openssl_" #name, https_##name##_test, TT_ISOLATED, &basic_setup, NULL }
|
|
|
|
#define HTTPS_MBEDTLS(name) \
|
|
|
|
{ "https_mbedtls_" #name, https_mbedtls_##name##_test, TT_ISOLATED, &mbedtls_setup, NULL }
|
2010-11-03 13:55:20 -04:00
|
|
|
|
2015-11-06 10:13:13 +03:00
|
|
|
#ifdef EVENT__HAVE_OPENSSL
|
|
|
|
static void https_basic_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_basic_test_impl(arg, HTTP_OPENSSL, "GET /test HTTP/1.1"); }
|
2016-12-07 03:07:59 +03:00
|
|
|
static void https_filter_basic_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_basic_test_impl(arg, HTTP_OPENSSL | HTTP_SSL_FILTER, "GET /test HTTP/1.1"); }
|
2015-11-06 10:13:13 +03:00
|
|
|
static void https_incomplete_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_incomplete_test_(arg, 0, HTTP_OPENSSL); }
|
2015-11-06 10:13:13 +03:00
|
|
|
static void https_incomplete_timeout_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_incomplete_test_(arg, 1, HTTP_OPENSSL); }
|
2015-11-06 10:13:13 +03:00
|
|
|
static void https_simple_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_simple_test_impl(arg, HTTP_OPENSSL, 0, "/test"); }
|
2015-11-06 10:13:13 +03:00
|
|
|
static void https_simple_dirty_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_simple_test_impl(arg, HTTP_OPENSSL, 1, "/test"); }
|
2015-11-06 10:13:13 +03:00
|
|
|
static void https_connection_retry_conn_address_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_connection_retry_conn_address_test_impl(arg, HTTP_OPENSSL); }
|
2015-11-06 10:13:13 +03:00
|
|
|
static void https_connection_retry_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_connection_retry_test_impl(arg, HTTP_OPENSSL); }
|
2015-11-06 15:58:41 +03:00
|
|
|
static void https_chunk_out_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_chunk_out_test_impl(arg, HTTP_OPENSSL); }
|
2016-12-07 03:07:59 +03:00
|
|
|
static void https_filter_chunk_out_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_chunk_out_test_impl(arg, HTTP_OPENSSL | HTTP_SSL_FILTER); }
|
2015-11-15 00:05:00 +03:00
|
|
|
static void https_stream_out_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_stream_out_test_impl(arg, HTTP_OPENSSL); }
|
2015-11-15 00:08:24 +03:00
|
|
|
static void https_connection_fail_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_connection_fail_test_impl(arg, HTTP_OPENSSL); }
|
2015-11-15 00:12:25 +03:00
|
|
|
static void https_write_during_read_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_write_during_read_test_impl(arg, HTTP_OPENSSL); }
|
2016-11-19 15:54:52 +03:00
|
|
|
static void https_connection_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_UNSPEC, HTTP_OPENSSL); }
|
2016-11-19 15:54:52 +03:00
|
|
|
static void https_persist_connection_test(void *arg)
|
2020-09-06 15:33:32 +08:00
|
|
|
{ http_connection_test_(arg, 1, "127.0.0.1", NULL, 0, AF_UNSPEC, HTTP_OPENSSL); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EVENT__HAVE_MBEDTLS
|
|
|
|
static void https_mbedtls_basic_test(void *arg)
|
|
|
|
{ http_basic_test_impl(arg, HTTP_MBEDTLS, "GET /test HTTP/1.1"); }
|
|
|
|
static void https_mbedtls_filter_basic_test(void *arg)
|
|
|
|
{ http_basic_test_impl(arg, HTTP_MBEDTLS | HTTP_SSL_FILTER, "GET /test HTTP/1.1"); }
|
|
|
|
static void https_mbedtls_incomplete_test(void *arg)
|
|
|
|
{ http_incomplete_test_(arg, 0, HTTP_MBEDTLS); }
|
|
|
|
static void https_mbedtls_incomplete_timeout_test(void *arg)
|
|
|
|
{ http_incomplete_test_(arg, 1, HTTP_MBEDTLS); }
|
|
|
|
static void https_mbedtls_simple_test(void *arg)
|
|
|
|
{ http_simple_test_impl(arg, HTTP_MBEDTLS, 0, "/test"); }
|
|
|
|
static void https_mbedtls_simple_dirty_test(void *arg)
|
|
|
|
{ http_simple_test_impl(arg, HTTP_MBEDTLS, 1, "/test"); }
|
|
|
|
static void https_mbedtls_connection_retry_conn_address_test(void *arg)
|
|
|
|
{ http_connection_retry_conn_address_test_impl(arg, HTTP_MBEDTLS); }
|
|
|
|
static void https_mbedtls_connection_retry_test(void *arg)
|
|
|
|
{ http_connection_retry_test_impl(arg, HTTP_MBEDTLS); }
|
|
|
|
static void https_mbedtls_chunk_out_test(void *arg)
|
|
|
|
{ http_chunk_out_test_impl(arg, HTTP_MBEDTLS); }
|
|
|
|
static void https_mbedtls_filter_chunk_out_test(void *arg)
|
|
|
|
{ http_chunk_out_test_impl(arg, HTTP_MBEDTLS | HTTP_SSL_FILTER); }
|
|
|
|
static void https_mbedtls_stream_out_test(void *arg)
|
|
|
|
{ http_stream_out_test_impl(arg, HTTP_MBEDTLS); }
|
|
|
|
static void https_mbedtls_connection_fail_test(void *arg)
|
|
|
|
{ http_connection_fail_test_impl(arg, HTTP_MBEDTLS); }
|
|
|
|
static void https_mbedtls_write_during_read_test(void *arg)
|
|
|
|
{ http_write_during_read_test_impl(arg, HTTP_MBEDTLS); }
|
|
|
|
static void https_mbedtls_connection_test(void *arg)
|
|
|
|
{ http_connection_test_(arg, 0, "127.0.0.1", NULL, 0, AF_UNSPEC, HTTP_MBEDTLS); }
|
|
|
|
static void https_mbedtls_persist_connection_test(void *arg)
|
|
|
|
{ http_connection_test_(arg, 1, "127.0.0.1", NULL, 0, AF_UNSPEC, HTTP_MBEDTLS); }
|
2015-11-06 10:13:13 +03:00
|
|
|
#endif
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
struct testcase_t http_testcases[] = {
|
|
|
|
{ "primitives", http_primitives, 0, NULL, NULL },
|
2010-11-03 15:04:44 -04:00
|
|
|
{ "base", http_base_test, TT_FORK, NULL, NULL },
|
2009-01-30 17:44:13 +00:00
|
|
|
{ "bad_headers", http_bad_header_test, 0, NULL, NULL },
|
2009-04-10 05:43:45 +00:00
|
|
|
{ "parse_query", http_parse_query_test, 0, NULL, NULL },
|
2018-10-27 17:36:09 +03:00
|
|
|
{ "parse_query_str", http_parse_query_str_test, 0, NULL, NULL },
|
2018-10-27 17:21:35 +03:00
|
|
|
{ "parse_query_str_flags", http_parse_query_str_flags_test, 0, NULL, NULL },
|
2010-08-08 16:46:39 +04:00
|
|
|
{ "parse_uri", http_parse_uri_test, 0, NULL, NULL },
|
2011-02-13 00:41:22 -05:00
|
|
|
{ "parse_uri_nc", http_parse_uri_test, 0, &basic_setup, (void*)"nc" },
|
2016-01-31 11:31:00 +00:00
|
|
|
{ "parse_uri_un", http_parse_uri_test, 0, &basic_setup, (void*)"un" },
|
|
|
|
{ "parse_uri_un_nc", http_parse_uri_test, 0, &basic_setup, (void*)"un_nc" },
|
2010-10-08 13:05:13 -04:00
|
|
|
{ "uriencode", http_uriencode_test, 0, NULL, NULL },
|
2010-11-03 13:55:20 -04:00
|
|
|
HTTP(basic),
|
2018-10-22 23:38:42 +03:00
|
|
|
HTTP(basic_trailing_space),
|
2015-11-05 12:39:35 +03:00
|
|
|
HTTP(simple),
|
2018-10-22 23:38:42 +03:00
|
|
|
HTTP(simple_nonconformant),
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
|
2019-04-03 07:26:21 +03:00
|
|
|
HTTP_N(cancel, cancel, 0, BASIC),
|
|
|
|
HTTP_RET_N(cancel_by_host, cancel, 0, BY_HOST),
|
|
|
|
HTTP_RET_N(cancel_by_host_inactive_server, cancel, TT_NO_LOGS, BY_HOST | INACTIVE_SERVER),
|
|
|
|
HTTP_RET_N(cancel_by_host_no_ns, cancel, TT_NO_LOGS, BY_HOST | NO_NS),
|
|
|
|
HTTP_N(cancel_inactive_server, cancel, 0, INACTIVE_SERVER),
|
|
|
|
HTTP_N(cancel_by_host_no_ns_inactive_server, cancel, TT_NO_LOGS, BY_HOST | NO_NS | INACTIVE_SERVER),
|
2017-01-07 11:48:28 +03:00
|
|
|
HTTP_OFF_N(cancel_by_host_server_timeout, cancel, BY_HOST | INACTIVE_SERVER | SERVER_TIMEOUT),
|
|
|
|
HTTP_OFF_N(cancel_server_timeout, cancel, INACTIVE_SERVER | SERVER_TIMEOUT),
|
|
|
|
HTTP_OFF_N(cancel_by_host_no_ns_server_timeout, cancel, BY_HOST | NO_NS | INACTIVE_SERVER | SERVER_TIMEOUT),
|
|
|
|
HTTP_OFF_N(cancel_by_host_ns_timeout_server_timeout, cancel, BY_HOST | NO_NS | NS_TIMEOUT | INACTIVE_SERVER | SERVER_TIMEOUT),
|
2019-04-03 07:26:21 +03:00
|
|
|
HTTP_RET_N(cancel_by_host_ns_timeout, cancel, TT_NO_LOGS, BY_HOST | NO_NS | NS_TIMEOUT),
|
|
|
|
HTTP_RET_N(cancel_by_host_ns_timeout_inactive_server, cancel, TT_NO_LOGS, BY_HOST | NO_NS | NS_TIMEOUT | INACTIVE_SERVER),
|
test/http: request cancellation with resolving/{conn,write}-timeouts in progress
This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout
This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.
Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok. (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403== in use at exit: 1,104 bytes in 5 blocks
==8403== total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403== by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x491EDD: evbuffer_new (buffer.c:365)
==8403== by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403== by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403== by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403== by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403== by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403== at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403== by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403== by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403== by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403== by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403== by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403== by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403== by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403== by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403== by 0x490C47: testcase_run_one (tinytest.c:252)
==8403== by 0x491586: tinytest_main (tinytest.c:434)
==8403== by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403== definitely lost: 264 bytes in 1 blocks
==8403== indirectly lost: 840 bytes in 4 blocks
==8403== possibly lost: 0 bytes in 0 blocks
==8403== still reachable: 0 bytes in 0 blocks
==8403== suppressed: 0 bytes in 0 blocks
2016-03-12 18:50:41 +03:00
|
|
|
|
2010-11-03 13:55:20 -04:00
|
|
|
HTTP(virtual_host),
|
2016-01-31 11:31:00 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
HTTP(unix_socket),
|
|
|
|
#endif
|
2010-11-03 13:55:20 -04:00
|
|
|
HTTP(post),
|
|
|
|
HTTP(put),
|
|
|
|
HTTP(delete),
|
2019-03-13 10:51:55 +03:00
|
|
|
HTTP(propfind),
|
|
|
|
HTTP(proppatch),
|
|
|
|
HTTP(mkcol),
|
|
|
|
HTTP(lock),
|
|
|
|
HTTP(unlock),
|
|
|
|
HTTP(copy),
|
|
|
|
HTTP(move),
|
2016-01-08 13:36:20 -08:00
|
|
|
HTTP(custom),
|
2010-11-04 12:41:13 -04:00
|
|
|
HTTP(allowed_methods),
|
2010-11-03 13:55:20 -04:00
|
|
|
HTTP(failure),
|
|
|
|
HTTP(connection),
|
|
|
|
HTTP(persist_connection),
|
2014-10-29 03:40:44 -04:00
|
|
|
HTTP(autofree_connection),
|
2010-11-03 13:55:20 -04:00
|
|
|
HTTP(connection_async),
|
|
|
|
HTTP(close_detection),
|
|
|
|
HTTP(close_detection_delay),
|
2010-11-03 14:31:23 -04:00
|
|
|
HTTP(bad_request),
|
2010-11-03 13:55:20 -04:00
|
|
|
HTTP(incomplete),
|
|
|
|
HTTP(incomplete_timeout),
|
2010-11-03 14:31:23 -04:00
|
|
|
HTTP(terminate_chunked),
|
2015-09-08 15:44:13 +03:00
|
|
|
HTTP(terminate_chunked_oneshot),
|
2014-01-05 20:35:46 -05:00
|
|
|
HTTP(on_complete),
|
2010-11-03 14:31:23 -04:00
|
|
|
|
|
|
|
HTTP(highport),
|
|
|
|
HTTP(dispatcher),
|
|
|
|
HTTP(multi_line_header),
|
|
|
|
HTTP(negative_content_length),
|
2021-01-18 23:23:42 +03:00
|
|
|
HTTP(send_chunk),
|
2010-11-03 14:31:23 -04:00
|
|
|
HTTP(chunk_out),
|
|
|
|
HTTP(stream_out),
|
|
|
|
|
|
|
|
HTTP(stream_in),
|
|
|
|
HTTP(stream_in_cancel),
|
|
|
|
|
2011-05-23 01:40:05 -04:00
|
|
|
HTTP(connection_fail),
|
2013-05-01 10:04:08 -04:00
|
|
|
{ "connection_retry", http_connection_retry_test, TT_ISOLATED|TT_OFF_BY_DEFAULT, &basic_setup, NULL },
|
2014-11-15 20:35:40 +03:00
|
|
|
{ "connection_retry_conn_address", http_connection_retry_conn_address_test,
|
|
|
|
TT_ISOLATED|TT_OFF_BY_DEFAULT, &basic_setup, NULL },
|
2013-05-01 10:04:08 -04:00
|
|
|
|
2021-09-19 12:56:24 +03:00
|
|
|
HTTP_OPT(data_length_constraints, SKIP_UNDER_WINDOWS|TT_RETRIABLE),
|
2016-03-11 19:25:11 +03:00
|
|
|
HTTP(read_on_write_error),
|
2016-02-15 03:13:02 +03:00
|
|
|
HTTP(non_lingering_close),
|
2016-02-15 03:21:39 +03:00
|
|
|
HTTP(lingering_close),
|
2009-01-30 17:44:13 +00:00
|
|
|
|
2013-01-27 02:17:02 +04:00
|
|
|
HTTP(ipv6_for_domain),
|
2013-10-01 19:54:09 +04:00
|
|
|
HTTP(get_addr),
|
2013-01-27 02:17:02 +04:00
|
|
|
|
2014-03-27 00:40:14 +04:00
|
|
|
HTTP(set_family),
|
|
|
|
HTTP(set_family_ipv4),
|
2014-03-27 00:49:00 +04:00
|
|
|
HTTP(set_family_ipv6),
|
2014-03-27 00:40:14 +04:00
|
|
|
|
2015-09-09 17:45:44 +03:00
|
|
|
HTTP(write_during_read),
|
2015-09-09 19:15:18 +03:00
|
|
|
HTTP(request_own),
|
2016-02-09 18:01:00 +00:00
|
|
|
HTTP(error_callback),
|
2015-09-09 17:45:44 +03:00
|
|
|
|
Fix crashing http server when callback do not reply in place
General http callback looks like:
static void http_cb(struct evhttp_request *req, void *arg)
{
evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
}
And they will work fine becuase in this case http will write request
first, and during write preparation it will disable *read callback* (in
evhttp_write_buffer()), but if we don't reply immediately, for example:
static void http_cb(struct evhttp_request *req, void *arg)
{
return;
}
This will leave connection in incorrect state, and if another request
will be written to the same connection libevent will abort with:
[err] ../http.c: illegal connection state 7
Because it thinks that read for now is not possible, since there were no
write.
Fix this by disabling EV_READ entirely. We couldn't just reset callbacks
because this will leave EOF detection, which we don't need, since user
hasn't replied to callback yet.
Reported-by: Cory Fields <cory@coryfields.com>
2017-10-23 00:13:37 +03:00
|
|
|
HTTP(request_extra_body),
|
|
|
|
|
2017-12-01 01:29:32 +00:00
|
|
|
HTTP(newreqcb),
|
2021-09-19 10:54:27 +03:00
|
|
|
HTTP_OPT(max_connections, SKIP_UNDER_WINDOWS),
|
2017-12-01 01:29:32 +00:00
|
|
|
|
2019-03-04 06:53:42 +03:00
|
|
|
HTTP(timeout_read_client),
|
|
|
|
HTTP(timeout_read_server),
|
|
|
|
|
2015-11-05 10:58:41 +03:00
|
|
|
#ifdef EVENT__HAVE_OPENSSL
|
2015-11-05 19:12:58 +03:00
|
|
|
HTTPS(basic),
|
2016-12-07 03:07:59 +03:00
|
|
|
HTTPS(filter_basic),
|
2015-11-05 12:39:35 +03:00
|
|
|
HTTPS(simple),
|
|
|
|
HTTPS(simple_dirty),
|
2015-11-05 19:08:30 +03:00
|
|
|
HTTPS(incomplete),
|
|
|
|
HTTPS(incomplete_timeout),
|
2015-11-05 11:17:07 +03:00
|
|
|
{ "https_connection_retry", https_connection_retry_test, TT_ISOLATED|TT_OFF_BY_DEFAULT, &basic_setup, NULL },
|
|
|
|
{ "https_connection_retry_conn_address", https_connection_retry_conn_address_test,
|
|
|
|
TT_ISOLATED|TT_OFF_BY_DEFAULT, &basic_setup, NULL },
|
2015-11-06 15:58:41 +03:00
|
|
|
HTTPS(chunk_out),
|
2016-12-07 03:07:59 +03:00
|
|
|
HTTPS(filter_chunk_out),
|
2015-11-15 00:05:00 +03:00
|
|
|
HTTPS(stream_out),
|
2015-11-15 00:08:24 +03:00
|
|
|
HTTPS(connection_fail),
|
2015-11-15 00:12:25 +03:00
|
|
|
HTTPS(write_during_read),
|
2016-11-19 15:54:52 +03:00
|
|
|
HTTPS(connection),
|
|
|
|
HTTPS(persist_connection),
|
2015-11-05 10:58:41 +03:00
|
|
|
#endif
|
|
|
|
|
2020-09-06 15:33:32 +08:00
|
|
|
#ifdef EVENT__HAVE_MBEDTLS
|
|
|
|
HTTPS_MBEDTLS(basic),
|
|
|
|
HTTPS_MBEDTLS(filter_basic),
|
|
|
|
HTTPS_MBEDTLS(simple),
|
|
|
|
HTTPS_MBEDTLS(simple_dirty),
|
|
|
|
HTTPS_MBEDTLS(incomplete),
|
|
|
|
HTTPS_MBEDTLS(incomplete_timeout),
|
|
|
|
{ "https_mbedtls_connection_retry", https_mbedtls_connection_retry_test, TT_ISOLATED|TT_OFF_BY_DEFAULT, &basic_setup, NULL },
|
|
|
|
{ "https_mbedtls_connection_retry_conn_address", https_mbedtls_connection_retry_conn_address_test,
|
|
|
|
TT_ISOLATED|TT_OFF_BY_DEFAULT, &basic_setup, NULL },
|
|
|
|
HTTPS_MBEDTLS(chunk_out),
|
|
|
|
HTTPS_MBEDTLS(filter_chunk_out),
|
|
|
|
HTTPS_MBEDTLS(stream_out),
|
|
|
|
HTTPS_MBEDTLS(connection_fail),
|
|
|
|
HTTPS_MBEDTLS(write_during_read),
|
|
|
|
HTTPS_MBEDTLS(connection),
|
|
|
|
HTTPS_MBEDTLS(persist_connection),
|
|
|
|
#endif
|
|
|
|
|
2009-01-30 17:44:13 +00:00
|
|
|
END_OF_TESTCASES
|
|
|
|
};
|
|
|
|
|
2018-11-13 11:25:35 +03:00
|
|
|
struct testcase_t http_iocp_testcases[] = {
|
|
|
|
{ "simple", http_simple_test, TT_FORK|TT_NEED_BASE|TT_ENABLE_IOCP, &basic_setup, NULL },
|
2018-11-20 06:20:51 +03:00
|
|
|
#ifdef EVENT__HAVE_OPENSSL
|
2020-09-15 18:15:24 +08:00
|
|
|
{ "https_openssl_simple", https_simple_test, TT_FORK|TT_NEED_BASE|TT_ENABLE_IOCP, &basic_setup, NULL },
|
2020-09-06 15:33:32 +08:00
|
|
|
#endif
|
|
|
|
#ifdef EVENT__HAVE_MBEDTLS
|
2020-09-15 18:15:24 +08:00
|
|
|
{ "https_mbedtls_simple", https_mbedtls_simple_test, TT_FORK|TT_NEED_BASE|TT_ENABLE_IOCP, &mbedtls_setup, NULL },
|
2018-11-20 06:20:51 +03:00
|
|
|
#endif
|
2018-11-13 11:25:35 +03:00
|
|
|
END_OF_TESTCASES
|
|
|
|
};
|