aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/supplemental/websocket/websocket.c2
-rw-r--r--src/supplemental/websocket/websocket_test.c19
2 files changed, 21 insertions, 0 deletions
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c
index b215c1da..8c622be6 100644
--- a/src/supplemental/websocket/websocket.c
+++ b/src/supplemental/websocket/websocket.c
@@ -2126,6 +2126,7 @@ nni_ws_listener_alloc(nng_stream_listener **wslp, const nng_url *url)
NNI_LIST_INIT(&l->pend, nni_ws, node);
NNI_LIST_INIT(&l->reply, nni_ws, node);
+ NNI_LIST_INIT(&l->headers, ws_header, node);
// make a private copy of the url structure.
if ((rv = nng_url_clone(&l->url, url)) != 0) {
@@ -2651,6 +2652,7 @@ nni_ws_dialer_alloc(nng_stream_dialer **dp, const nng_url *url)
}
NNI_LIST_INIT(&d->headers, ws_header, node);
NNI_LIST_INIT(&d->wspend, nni_ws, node);
+ NNI_LIST_INIT(&d->headers, ws_header, node);
nni_mtx_init(&d->mtx);
nni_cv_init(&d->cv, &d->mtx);
diff --git a/src/supplemental/websocket/websocket_test.c b/src/supplemental/websocket/websocket_test.c
index f648f740..781ca1d8 100644
--- a/src/supplemental/websocket/websocket_test.c
+++ b/src/supplemental/websocket/websocket_test.c
@@ -146,6 +146,12 @@ test_websocket_conn_props(void)
NUTS_PASS(nng_stream_listener_listen(l));
NUTS_PASS(nng_stream_dialer_alloc(&d, uri));
+ NUTS_PASS(nng_stream_dialer_set_string(
+ d, NNG_OPT_WS_REQUEST_HEADER "NNG-Req", "True"));
+
+ NUTS_PASS(nng_stream_listener_set_string(
+ l, NNG_OPT_WS_RESPONSE_HEADER "NNG-Rep", "True"));
+
nng_stream_dialer_dial(d, daio);
nng_stream_listener_accept(l, laio);
@@ -180,6 +186,19 @@ test_websocket_conn_props(void)
NUTS_FAIL(
nng_stream_get_size(c1, NNG_OPT_TCP_NODELAY, &sz), NNG_EBADTYPE);
+ NUTS_FAIL(nng_stream_get_string(
+ c1, NNG_OPT_WS_REQUEST_HEADER "No-Such-Header", &str),
+ NNG_ENOENT);
+ NUTS_PASS(nng_stream_get_string(
+ c1, NNG_OPT_WS_REQUEST_HEADER "NNG-Req", &str));
+ NUTS_MATCH(str, "True");
+ nng_strfree(str);
+
+ NUTS_PASS(nng_stream_get_string(
+ c2, NNG_OPT_WS_RESPONSE_HEADER "NNG-Rep", &str));
+ NUTS_MATCH(str, "True");
+ nng_strfree(str);
+
NUTS_PASS(nng_stream_get_string(
c1, NNG_OPT_WS_REQUEST_HEADER "Sec-WebSocket-Version", &str));
NUTS_TRUE(str != NULL);