Fix forbidden answer.

This commit is contained in:
Преподобный Ален
2025-11-26 14:34:39 +03:00
parent 1657e93861
commit 9df05fc88b

View File

@@ -85,7 +85,7 @@ namespace Apostol {
while (index < m_Servers.Count()) {
const auto &caContext = m_Servers[index].Value();
if (caContext.Status() == Context::csRunning) {
if (Params == caContext.Name() || Params == caContext.URL().Origin()) {
if (Params.IsEmpty() || Params == caContext.Name() || Params == caContext.URL().Origin()) {
return index;
}
}
@@ -99,11 +99,11 @@ namespace Apostol {
bool CWebService::DoProxyExecute(CTCPConnection *AConnection) {
auto pConnection = dynamic_cast<CHTTPClientConnection *> (AConnection);
auto pProxy = dynamic_cast<CHTTPProxy *> (pConnection->Client());
const auto pConnection = dynamic_cast<CHTTPClientConnection *> (AConnection);
const auto pProxy = dynamic_cast<CHTTPProxy *> (pConnection->Client());
if (Assigned(pProxy) && (pProxy->Connection() != nullptr)) {
auto pProxyConnection = pProxy->Connection();
if (Assigned(pProxy) && pProxy->Connection() != nullptr) {
const auto pProxyConnection = pProxy->Connection();
const auto &caServerRequest = pProxyConnection->Request();
auto &ServerReply = pProxyConnection->Reply();
const auto &caProxyReply = pConnection->Reply();
@@ -145,9 +145,20 @@ namespace Apostol {
}
} else {
ServerReply.Content = caProxyReply.Content;
if (caProxyReply.Status == CHTTPReply::ok) {
pProxyConnection->SendReply(caProxyReply.Status, nullptr, true);
} else {
if (caProxyReply.Status == CHTTPReply::forbidden) {
const auto &caServerParam = caServerRequest.Params["server"];
const auto index = CurrentContextIndex(caServerParam);
auto &Context = index == -1 ? m_CurrentServer : m_Servers[index].Value();
Context.SetCheckDate(0);
Context.SetStatus(Context::csInitialized);
}
pProxyConnection->SendStockReply(caProxyReply.Status, true);
}
}
@@ -160,8 +171,8 @@ namespace Apostol {
//--------------------------------------------------------------------------------------------------------------
void CWebService::DoProxyException(CTCPConnection *AConnection, const Delphi::Exception::Exception &E) {
auto pConnection = dynamic_cast<CHTTPClientConnection*> (AConnection);
auto pProxy = dynamic_cast<CHTTPProxy*> (pConnection->Client());
const auto pConnection = dynamic_cast<CHTTPClientConnection*> (AConnection);
const auto pProxy = dynamic_cast<CHTTPProxy*> (pConnection->Client());
if (Assigned(pProxy) && (pProxy->Connection() != nullptr)) {
auto pProxyConnection = pProxy->Connection();
@@ -209,7 +220,7 @@ namespace Apostol {
//--------------------------------------------------------------------------------------------------------------
void CWebService::DoProxyDisconnected(CObject *Sender) {
auto pConnection = dynamic_cast<CHTTPClientConnection*> (Sender);
const auto pConnection = dynamic_cast<CHTTPClientConnection*> (Sender);
if (pConnection != nullptr) {
Log()->Message(_T("[%s:%d] Client disconnected."), pConnection->Socket()->Binding()->PeerIP(),
pConnection->Socket()->Binding()->PeerPort());
@@ -927,7 +938,7 @@ namespace Apostol {
void CWebService::DoProxy(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) {
auto pProxy = GetProxy(AConnection);
const auto pProxy = GetProxy(AConnection);
const auto &caServerRequest = AConnection->Request();
auto &ProxyRequest = pProxy->Request();
@@ -938,7 +949,6 @@ namespace Apostol {
if (checkFee == -1)
throw ExceptionFrm("Invalid module fee value: %s", caModuleFee.c_str());
const auto &caHost = caServerRequest.Headers["host"];
const auto &caOrigin = caServerRequest.Headers["origin"];
const auto &caContentType = caServerRequest.Headers["content-type"].Lower();