diff --git a/test/request.c b/test/request.c index 479fbf31..e9e0e720 100644 --- a/test/request.c +++ b/test/request.c @@ -1976,9 +1976,14 @@ static int status(void) { ne_session *sess; ne_buffer *buf = ne_buffer_create(); - const char *lh_addr = get_lh_addr(); + const char *host, *addr = get_lh_addr(); char expect[1024]; + CALL(make_session(&sess, single_serve_string, RESP200 + "Content-Length: 5\r\n\r\n" "abcde")); + + host = get_session_host(); + ne_snprintf(expect, sizeof expect, "lookup(%s)-" "connecting(%s,%s)-" @@ -1988,10 +1993,7 @@ static int status(void) "recv(0,5)-" "recv(5,5)-" "disconnected(%s)-", - lh_addr, lh_addr, lh_addr, lh_addr, lh_addr); - - CALL(make_session(&sess, single_serve_string, RESP200 - "Content-Length: 5\r\n\r\n" "abcde")); + host, host, addr, host, host); ne_set_notifier(sess, status_cb, buf); @@ -2012,9 +2014,14 @@ static int status_chunked(void) { ne_session *sess; ne_buffer *buf = ne_buffer_create(); - const char *lh_addr = get_lh_addr(); + const char *host, *addr = get_lh_addr(); char expect[1024]; + CALL(make_session(&sess, single_serve_string, + RESP200 TE_CHUNKED "\r\n" ABCDE_CHUNKS)); + + host = get_session_host(); + /* This sequence is not exactly guaranteed by the API, but it's * what the current implementation should do. */ ne_snprintf(expect, sizeof expect, @@ -2030,10 +2037,7 @@ static int status_chunked(void) "recv(4,-1)-" "recv(5,-1)-" "disconnected(%s)-", - lh_addr, lh_addr, lh_addr, lh_addr, lh_addr); - - CALL(make_session(&sess, single_serve_string, - RESP200 TE_CHUNKED "\r\n" ABCDE_CHUNKS)); + host, host, addr, host, host); ne_set_notifier(sess, status_cb, buf); diff --git a/test/utils.c b/test/utils.c index 003e13b3..377762f7 100644 --- a/test/utils.c +++ b/test/utils.c @@ -36,6 +36,8 @@ #include "tests.h" #include "utils.h" +static char session_host[128]; + int serve_response(ne_socket *s, const char *response) { CALL(discard_request(s)); @@ -204,22 +206,23 @@ int multi_session_server(ne_session **sess, return OK; } +const char *get_session_host(void) +{ + return session_host; +} + int session_server(ne_session **sess, server_fn fn, void *userdata) { - char *host6 = NULL; - const char *host; int ret; if (get_lh_family() == AF_INET6) { - host = host6 = ne_concat("[", get_lh_addr(), "]", NULL); + ne_snprintf(session_host, sizeof session_host, "[%s]", get_lh_addr()); } else { - host = get_lh_addr(); + ne_strnzcpy(session_host, get_lh_addr(), sizeof session_host); } - ret = multi_session_server(sess, "http", host, 1, fn, userdata); - - if (host6) ne_free(host6); + ret = multi_session_server(sess, "http", session_host, 1, fn, userdata); return ret; } diff --git a/test/utils.h b/test/utils.h index 126ba034..849b91f8 100644 --- a/test/utils.h +++ b/test/utils.h @@ -59,6 +59,9 @@ int any_2xx_request_method(ne_session *sess, const char *method, * CALL(make_session(...)); */ int make_session(ne_session **sess, server_fn fn, void *userdata); +/* Returns hostname used for make_session(). */ +const char *get_session_host(void); + /* Server which sleeps for 10 seconds then closes the socket. */ int sleepy_server(ne_socket *sock, void *userdata);