mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
test/http: cover evhttp_connection_get_addr() for incomming connections
Refs: #510
This commit is contained in:
parent
367cd9e5c2
commit
e4edc7fc27
@ -314,12 +314,31 @@ http_basic_cb(struct evhttp_request *req, void *arg)
|
||||
struct evbuffer *evb = evbuffer_new();
|
||||
struct evhttp_connection *evcon;
|
||||
int empty = evhttp_find_header(evhttp_request_get_input_headers(req), "Empty") != NULL;
|
||||
|
||||
event_debug(("%s: called\n", __func__));
|
||||
evbuffer_add_printf(evb, BASIC_REQUEST_BODY);
|
||||
|
||||
evcon = evhttp_request_get_connection(req);
|
||||
tt_assert(evhttp_connection_get_server(evcon) == arg);
|
||||
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
/* For multi-line headers test */
|
||||
{
|
||||
const char *multi =
|
||||
|
Loading…
x
Reference in New Issue
Block a user