From 43a25d3f11edcc5fbb9dbba1662bbaae92e005ab Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 9 Jan 2024 14:46:44 +0300 Subject: code cleaning --- src/mir_app/src/netlib_autoproxy.cpp | 2 +- src/mir_app/src/netlib_websocket.cpp | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/mir_app/src/netlib_autoproxy.cpp b/src/mir_app/src/netlib_autoproxy.cpp index f030b76f2f..e20577b02d 100644 --- a/src/mir_app/src/netlib_autoproxy.cpp +++ b/src/mir_app/src/netlib_autoproxy.cpp @@ -52,7 +52,7 @@ static void GetFile(char *szUrl, AUTO_PROXY_SCRIPT_BUFFER &buf) nlu.toLog = 1; // initialize the netlib request - MHttpRequest nlhr(0); + MHttpRequest nlhr(REQUEST_GET); nlhr.flags = NLHRF_HTTP11 | NLHRF_DUMPASTEXT | NLHRF_REDIRECT; nlhr.m_szUrl = szUrl; diff --git a/src/mir_app/src/netlib_websocket.cpp b/src/mir_app/src/netlib_websocket.cpp index 1bd8f2e4cd..ab676b7a6a 100644 --- a/src/mir_app/src/netlib_websocket.cpp +++ b/src/mir_app/src/netlib_websocket.cpp @@ -35,28 +35,26 @@ MIR_APP_DLL(MHttpResponse*) WebSocket_Connect(HNETLIBUSER nlu, const char *szHos if (!mir_strncmp(tmpHost, "wss://", 6)) tmpHost.Delete(0, 6); - auto *nlr = new MHttpRequest(0); - nlr->flags = NLHRF_PERSISTENT | NLHRF_HTTP11 | NLHRF_SSL; - nlr->m_szUrl = tmpHost.GetBuffer(); - nlr->AddHeader("Accept", "*/*"); - nlr->AddHeader("Upgrade", "websocket"); - nlr->AddHeader("Pragma", "no-cache"); - nlr->AddHeader("Cache-Control", "no-cache"); - nlr->AddHeader("Connection", "keep-alive, Upgrade"); + MHttpRequest nlhr(REQUEST_GET); + nlhr.flags = NLHRF_PERSISTENT | NLHRF_HTTP11 | NLHRF_SSL; + nlhr.m_szUrl = tmpHost.GetBuffer(); + nlhr.AddHeader("Accept", "*/*"); + nlhr.AddHeader("Upgrade", "websocket"); + nlhr.AddHeader("Pragma", "no-cache"); + nlhr.AddHeader("Cache-Control", "no-cache"); + nlhr.AddHeader("Connection", "keep-alive, Upgrade"); uint8_t binNonce[16]; Utils_GetRandom(binNonce, sizeof(binNonce)); - nlr->AddHeader("Sec-WebSocket-Key", ptrA(mir_base64_encode(binNonce, sizeof(binNonce)))); - nlr->AddHeader("Sec-WebSocket-Version", "13"); - nlr->AddHeader("Sec-WebSocket-Extensions", "permessage-deflate; client_max_window_bits"); + nlhr.AddHeader("Sec-WebSocket-Key", ptrA(mir_base64_encode(binNonce, sizeof(binNonce)))); + nlhr.AddHeader("Sec-WebSocket-Version", "13"); + nlhr.AddHeader("Sec-WebSocket-Extensions", "permessage-deflate; client_max_window_bits"); if (pHeaders) for (auto &it: *pHeaders) - nlr->AddHeader(it->szName, it->szValue); - - auto *pReply = Netlib_HttpTransaction(nlu, nlr); - delete nlr; + nlhr.AddHeader(it->szName, it->szValue); + auto *pReply = Netlib_HttpTransaction(nlu, &nlhr); if (pReply == nullptr) { Netlib_Logf(nlu, "Error establishing WebSocket connection to %s, send failed", tmpHost.c_str()); return nullptr; -- cgit v1.2.3