Committing updates.
This commit is contained in:
@@ -521,7 +521,7 @@ namespace Apostol {
|
||||
} else if (caCommand == "signature") {
|
||||
DoSignature(AConnection);
|
||||
} else {
|
||||
AConnection->SendStockReply(CHTTPReply::not_found);
|
||||
DoProxy(AConnection, "POST", sRoute);
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
ReplyError(AConnection, CHTTPReply::bad_request, e.what());
|
||||
@@ -647,7 +647,7 @@ namespace Apostol {
|
||||
|
||||
} else {
|
||||
|
||||
AConnection->SendStockReply(CHTTPReply::not_found);
|
||||
DoProxy(AConnection, "GET", sRoute);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ namespace Apostol {
|
||||
|
||||
virtual void DoAccount(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) abstract;
|
||||
virtual void DoDeal(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI, const CString &Action) abstract;
|
||||
virtual void DoProxy(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) abstract;
|
||||
virtual void DoSignature(CHTTPServerConnection *AConnection) abstract;
|
||||
|
||||
public:
|
||||
|
||||
@@ -436,6 +436,8 @@ namespace Apostol {
|
||||
pProxyRequest->AddHeader("Origin", caOrigin);
|
||||
|
||||
AConnection->CloseConnection(false);
|
||||
|
||||
pProxy->AutoFree(true);
|
||||
pProxy->Active(true);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
@@ -852,6 +854,73 @@ namespace Apostol {
|
||||
|
||||
AConnection->CloseConnection(false);
|
||||
|
||||
pProxy->AutoFree(true);
|
||||
pProxy->Active(true);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void CWebService::DoProxy(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) {
|
||||
|
||||
auto pProxy = GetProxy(AConnection);
|
||||
auto pServerRequest = AConnection->Request();
|
||||
auto pProxyRequest = pProxy->Request();
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
const auto &caModuleFee = m_Module["fee"];
|
||||
|
||||
const auto checkFee = CheckFee(caModuleFee);
|
||||
if (checkFee == -1)
|
||||
throw ExceptionFrm("Invalid module fee value: %s", caModuleFee.c_str());
|
||||
|
||||
const auto &caHost = pServerRequest->Headers["host"];
|
||||
const auto &caOrigin = pServerRequest->Headers["origin"];
|
||||
|
||||
const auto &address = pServerRequest->Params["address"];
|
||||
const auto &code = pServerRequest->Params["code"];
|
||||
|
||||
const auto &caUserAddress = address.length() == 40 ? CString() : address;
|
||||
const auto &caDealCode = !code.empty() ? code : address.length() == 40 ? address : CString();
|
||||
|
||||
const auto &pgpValue = pServerRequest->Params["pgp"];
|
||||
const auto &caServerParam = pServerRequest->Params["server"];
|
||||
|
||||
const auto &caServer = caServerParam.IsEmpty() ? m_CurrentServer.URL().Origin() : caServerParam;
|
||||
|
||||
CLocation Location(caServer);
|
||||
|
||||
pProxy->Host() = Location.hostname;
|
||||
pProxy->Port(Location.port == 0 ? BPS_SERVER_PORT : Location.port);
|
||||
|
||||
pProxyRequest->Clear();
|
||||
|
||||
pProxyRequest->Location = pServerRequest->Location;
|
||||
pProxyRequest->ContentType = pServerRequest->ContentType;
|
||||
|
||||
if (Method == "POST") {
|
||||
pProxyRequest->Content = pServerRequest->Content;
|
||||
}
|
||||
|
||||
pProxyRequest->CloseConnection = true;
|
||||
|
||||
CHTTPRequest::Prepare(pProxyRequest, Method.c_str(), URI.c_str());
|
||||
|
||||
pProxyRequest->AddHeader("Authorization", "Bearer " + m_CurrentServer.Tokens()["access_token"]);
|
||||
|
||||
if (!caModuleAddress.IsEmpty())
|
||||
pProxyRequest->AddHeader("Module-Address", caModuleAddress);
|
||||
|
||||
if (!caModuleFee.IsEmpty())
|
||||
pProxyRequest->AddHeader("Module-Fee", caModuleFee);
|
||||
|
||||
if (!caOrigin.IsEmpty())
|
||||
pProxyRequest->AddHeader("Origin", caOrigin);
|
||||
|
||||
AConnection->TimeOutInterval(15 * 1000);
|
||||
AConnection->UpdateTimeOut(Now());
|
||||
|
||||
AConnection->CloseConnection(false);
|
||||
|
||||
pProxy->AutoFree(true);
|
||||
pProxy->Active(true);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace Apostol {
|
||||
|
||||
void DoAccount(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) override;
|
||||
void DoDeal(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI, const CString &Action) override;
|
||||
void DoProxy(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) override;
|
||||
void DoSignature(CHTTPServerConnection *AConnection) override;
|
||||
|
||||
bool DoProxyExecute(CTCPConnection *AConnection);
|
||||
|
||||
@@ -964,6 +964,60 @@ namespace Apostol {
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void CWebSocketModule::DoProxy(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) {
|
||||
|
||||
auto OnRequest = [AConnection](CWebSocketMessageHandler *AHandler, CWebSocketConnection *AWSConnection) {
|
||||
auto pReply = AConnection->Reply();
|
||||
const auto &wsMessage = CCustomWebSocketClient::RequestToMessage(AWSConnection);
|
||||
pReply->ContentType = CHTTPReply::json;
|
||||
if (wsMessage.MessageTypeId == mtCallResult) {
|
||||
pReply->Content = wsMessage.Payload.ToString();
|
||||
AConnection->SendReply(CHTTPReply::ok, nullptr, true);
|
||||
} else {
|
||||
ReplyError(AConnection, CHTTPReply::bad_request, wsMessage.ErrorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
auto pServerRequest = AConnection->Request();
|
||||
|
||||
const auto &caModuleAddress = m_Module["address"];
|
||||
const auto &caModuleFee = m_Module["fee"];
|
||||
|
||||
const auto checkFee = CheckFee(caModuleFee);
|
||||
if (checkFee == -1)
|
||||
throw ExceptionFrm("Invalid module fee value: %s", caModuleFee.c_str());
|
||||
|
||||
const auto &caHost = pServerRequest->Headers["host"];
|
||||
const auto &caOrigin = pServerRequest->Headers["origin"];
|
||||
|
||||
const auto &address = pServerRequest->Params["address"];
|
||||
const auto &code = pServerRequest->Params["code"];
|
||||
|
||||
const auto &caUserAddress = address.length() == 40 ? CString() : address;
|
||||
const auto &caDealCode = !code.empty() ? code : address.length() == 40 ? address : CString();
|
||||
|
||||
const auto &pgpValue = pServerRequest->Params["pgp"];
|
||||
const auto &caServerParam = pServerRequest->Params["server"];
|
||||
|
||||
const auto index = CurrentContextIndex(caServerParam);
|
||||
if (index == -1) {
|
||||
throw Delphi::Exception::Exception(NOT_FOUND_ACTIVE_CONNECTION);
|
||||
}
|
||||
|
||||
const auto &caContext = m_Servers[index].Value();
|
||||
|
||||
auto pClient = GetConnectedClient(caContext);
|
||||
|
||||
if (pClient == nullptr) {
|
||||
throw Delphi::Exception::Exception(NOT_FOUND_ACTIVE_CONNECTION);
|
||||
}
|
||||
|
||||
const CJSON Json(pServerRequest->Content);
|
||||
|
||||
pClient->Send(URI, Json, OnRequest);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void CWebSocketModule::DoSignature(CHTTPServerConnection *AConnection) {
|
||||
auto pRequest = AConnection->Request();
|
||||
auto pReply = AConnection->Reply();
|
||||
|
||||
@@ -88,6 +88,7 @@ namespace Apostol {
|
||||
|
||||
void DoAccount(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) override;
|
||||
void DoDeal(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI, const CString &Action) override;
|
||||
void DoProxy(CHTTPServerConnection *AConnection, const CString &Method, const CString &URI) override;
|
||||
void DoSignature(CHTTPServerConnection *AConnection) override;
|
||||
|
||||
void DoWebSocketError(CTCPConnection *AConnection);
|
||||
|
||||
Reference in New Issue
Block a user