diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c index 7d606b5c3..0ab4a167f 100644 --- a/src/supplemental/websocket/websocket.c +++ b/src/supplemental/websocket/websocket.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2019 Devolutions // @@ -1240,9 +1240,7 @@ ws_fini(void *arg) nni_mtx_unlock(&ws->mtx); - if (ws->http) { - nni_http_conn_fini(ws->http); - } + nni_http_conn_fini(ws->http); nni_strfree(ws->reqhdrs); nni_strfree(ws->reshdrs); @@ -2147,7 +2145,6 @@ ws_conn_cb(void *arg) nni_ws_dialer *d; nni_ws *ws; nni_aio *uaio; - nni_http_conn *http; nni_http_req *req = NULL; int rv; uint8_t raw[16]; @@ -2179,13 +2176,12 @@ ws_conn_cb(void *arg) return; } + ws->http = nni_aio_get_output(&ws->connaio, 0); nni_mtx_lock(&ws->mtx); uaio = ws->useraio; - http = nni_aio_get_output(&ws->connaio, 0); nni_aio_set_output(&ws->connaio, 0, NULL); if (uaio == NULL) { // This request was canceled for some reason. - nni_http_conn_fini(http); nni_mtx_unlock(&ws->mtx); ws_reap(ws); return; @@ -2197,8 +2193,10 @@ ws_conn_cb(void *arg) nni_base64_encode(raw, 16, wskey, 24); wskey[24] = '\0'; + req = nni_http_conn_req(ws->http); + #define SETH(h, v) nni_http_req_set_header(req, h, v) - if ((rv != 0) || ((rv = nni_http_req_alloc(&req, d->url)) != 0) || + if ((rv != 0) || ((rv = nni_http_req_set_url(req, d->url)) != 0) || ((rv = SETH("Upgrade", "websocket")) != 0) || ((rv = SETH("Connection", "Upgrade")) != 0) || ((rv = SETH("Sec-WebSocket-Key", wskey)) != 0) || @@ -2218,22 +2216,15 @@ ws_conn_cb(void *arg) } #undef SETH - ws->http = http; - ws->req = req; + ws->req = req; - nni_http_write_req(http, req, &ws->httpaio); + nni_http_write_req(ws->http, req, &ws->httpaio); nni_mtx_unlock(&ws->mtx); return; err: nni_aio_finish_error(uaio, rv); nni_mtx_unlock(&ws->mtx); - if (http != NULL) { - nni_http_conn_fini(http); - } - if (req != NULL) { - nni_http_req_free(req); - } ws_reap(ws); }