From 001bebe75a72f5fc545f50d2c4ad8d46fbb4e2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=BF=D0=BE=D0=B4=D0=BE=D0=B1=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BD?= Date: Fri, 3 Mar 2023 20:46:09 +0300 Subject: [PATCH] Committing updates. --- src/modules/Workers/WebService/WebService.cpp | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/src/modules/Workers/WebService/WebService.cpp b/src/modules/Workers/WebService/WebService.cpp index eeda685..d67043e 100644 --- a/src/modules/Workers/WebService/WebService.cpp +++ b/src/modules/Workers/WebService/WebService.cpp @@ -106,7 +106,10 @@ namespace Apostol { auto pProxyConnection = pProxy->Connection(); const auto &caServerRequest = pProxyConnection->Request(); auto &ServerReply = pProxyConnection->Reply(); - auto &ProxyReply = pConnection->Reply(); + const auto &caProxyReply = pConnection->Reply(); + + DebugRequest(pConnection->Request()); + DebugReply(caProxyReply); const auto &caFormat = caServerRequest.Params["payload"]; if (!caFormat.IsEmpty()) { @@ -120,14 +123,14 @@ namespace Apostol { ServerReply.ContentType = CHTTPReply::text; } - if (ProxyReply.Status == CHTTPReply::ok) { - if (!ProxyReply.Content.IsEmpty()) { - const CJSON json(ProxyReply.Content); + if (caProxyReply.Status == CHTTPReply::ok) { + if (!caProxyReply.Content.IsEmpty()) { + const CJSON json(caProxyReply.Content); ServerReply.Content = base64_decode(json["payload"].AsString()); } - pProxyConnection->SendReply(ProxyReply.Status, nullptr, true); + pProxyConnection->SendReply(caProxyReply.Status, nullptr, true); } else { - if (ProxyReply.Status == CHTTPReply::forbidden) { + if (caProxyReply.Status == CHTTPReply::forbidden) { const auto &caServerParam = caServerRequest.Params["server"]; const auto index = CurrentContextIndex(caServerParam); @@ -137,15 +140,15 @@ namespace Apostol { Context.SetStatus(Context::csInitialized); } - ServerReply.Content = ProxyReply.Content; - pProxyConnection->SendStockReply(ProxyReply.Status, true); + ServerReply.Content = caProxyReply.Content; + pProxyConnection->SendStockReply(caProxyReply.Status, true); } } else { - ServerReply.Content = ProxyReply.Content; - if (ProxyReply.Status == CHTTPReply::ok) { - pProxyConnection->SendReply(ProxyReply.Status, nullptr, true); + ServerReply.Content = caProxyReply.Content; + if (caProxyReply.Status == CHTTPReply::ok) { + pProxyConnection->SendReply(caProxyReply.Status, nullptr, true); } else { - pProxyConnection->SendStockReply(ProxyReply.Status, true); + pProxyConnection->SendStockReply(caProxyReply.Status, true); } } } @@ -260,11 +263,6 @@ namespace Apostol { const auto &caContext = index == -1 ? m_CurrentServer : m_Servers[index].Value(); const auto &caServer = caContext.URL().Origin(); - CLocation Location(caServer); - - pProxy->Host() = Location.hostname; - pProxy->Port(Location.port == 0 ? BPS_SERVER_PORT : Location.port); - CStringList caClearText; CString sPayload; @@ -445,15 +443,22 @@ namespace Apostol { if (!sPayload.IsEmpty()) Json.Object().AddPair("payload", base64_encode(sPayload)); + CLocation Location(caServer); + + pProxy->Host() = Location.hostname; + pProxy->Port(Location.port == 0 ? BPS_SERVER_PORT : Location.port); + ProxyRequest.Clear(); - ProxyRequest.Location = caServerRequest.Location; + ProxyRequest.Location = Location.hostname + caServerRequest.Location.pathname + caServerRequest.Location.search; ProxyRequest.CloseConnection = false; ProxyRequest.ContentType = CHTTPRequest::json; ProxyRequest.Content << Json; CHTTPRequest::Prepare(ProxyRequest, "POST", URI.c_str()); + ProxyRequest.Headers.Values("Host", ProxyRequest.Location.Host()); + ProxyRequest.AddHeader("Authorization", "Bearer " + caContext.Tokens()["access_token"]); if (!caModuleAddress.IsEmpty()) @@ -465,6 +470,7 @@ namespace Apostol { AConnection->CloseConnection(false); pProxy->AutoFree(true); + pProxy->UsedSSL(Location.protocol == HTTPS_PREFIX); pProxy->Active(true); } //-------------------------------------------------------------------------------------------------------------- @@ -499,11 +505,6 @@ namespace Apostol { const auto &caContext = index == -1 ? m_CurrentServer : m_Servers[index].Value(); const auto &caServer = caContext.URL().Origin(); - CLocation Location(caServer); - - pProxy->Host() = Location.hostname; - pProxy->Port(Location.port == 0 ? BPS_SERVER_PORT : Location.port); - YAML::Node Node; CString sPayload; @@ -871,15 +872,22 @@ namespace Apostol { if (!sPayload.IsEmpty()) Json.Object().AddPair("payload", base64_encode(sPayload)); + CLocation Location(caServer); + + pProxy->Host() = Location.hostname; + pProxy->Port(Location.port == 0 ? BPS_SERVER_PORT : Location.port); + ProxyRequest.Clear(); - ProxyRequest.Location = caServerRequest.Location; + ProxyRequest.Location = Location.hostname + caServerRequest.Location.pathname + caServerRequest.Location.search; ProxyRequest.CloseConnection = true; ProxyRequest.ContentType = CHTTPRequest::json; ProxyRequest.Content << Json; CHTTPRequest::Prepare(ProxyRequest, "POST", URI.c_str()); + ProxyRequest.Headers.Values("Host", ProxyRequest.Location.Host()); + ProxyRequest.AddHeader("Authorization", "Bearer " + caContext.Tokens()["access_token"]); if (!caModuleAddress.IsEmpty()) @@ -897,6 +905,7 @@ namespace Apostol { AConnection->CloseConnection(false); pProxy->AutoFree(true); + pProxy->UsedSSL(Location.protocol == HTTPS_PREFIX); pProxy->Active(true); } //-------------------------------------------------------------------------------------------------------------- @@ -939,7 +948,8 @@ namespace Apostol { ProxyRequest.Clear(); - ProxyRequest.Location = caServerRequest.Location; + ProxyRequest.Location = Location.hostname + caServerRequest.Location.pathname + caServerRequest.Location.search; + ProxyRequest.Headers.Values("Host", ProxyRequest.Location.Host()); if (Method == "POST") { ProxyRequest.ContentType = StringToContentType(caContentType); @@ -967,6 +977,7 @@ namespace Apostol { AConnection->CloseConnection(false); pProxy->AutoFree(true); + pProxy->UsedSSL(Location.protocol == HTTPS_PREFIX); pProxy->Active(true); } //--------------------------------------------------------------------------------------------------------------