Committing updates.

This commit is contained in:
Преподобный Ален
2023-03-03 20:46:09 +03:00
parent 688d890c30
commit 001bebe75a

View File

@@ -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);
}
//--------------------------------------------------------------------------------------------------------------