public void Execute(HttpRequest request, HttpResponse response) { if (request.Server.EnableLog(LogType.Debug)) { request.Server.Log(LogType.Debug, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s get urlroute agent!"); } if (string.Compare(request.Method, "OPTIONS", true) == 0) { if (!string.IsNullOrEmpty(UrlRoute.AccessControlAllowOrigin)) { OptionsAttribute oa = new OptionsAttribute(); oa.AllowCredentials = UrlRoute.AccessControlAllowCredentials; oa.AllowHeaders = UrlRoute.AccessControlAllowHeaders; oa.AllowMaxAge = UrlRoute.AccessControlMaxAge > 0 ? UrlRoute.AccessControlMaxAge.ToString() : null; oa.AllowMethods = UrlRoute.AccessControlAllowMethods; oa.AllowOrigin = UrlRoute.AccessControlAllowOrigin; oa.Vary = UrlRoute.Vary; response.Result(oa); return; } } if (!UrlRoute.ValidateRPS()) { string error = $"Unable to reach [{UrlRoute.Url} route {request.Url}] in HTTP request, exceeding maximum number of rps limit"; Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response, UrlRoute.Gateway, error, Gateway.SERVER_MAX_OF_RPS); UrlRoute.Gateway.OnResponseError(erea); if (request.Server.EnableLog(LogType.Info)) { request.Server.Log(LogType.Info, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s route server exceeding maximum number of rps limit"); } return; } var agent = UrlRoute.GetServerAgent(request); if (agent == null) { if (request.Server.EnableLog(LogType.Info)) { request.Server.Log(LogType.Info, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s route server unavailable"); } Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs( request, response, UrlRoute.Gateway, $"The {Url} url route server unavailable", Gateway.URL_NODE_SERVER_UNAVAILABLE); UrlRoute.Gateway.OnResponseError(erea); } else { if (request.Server.EnableLog(LogType.Debug)) { request.Server.Log(LogType.Debug, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s AgentRequesting event!"); } if (UrlRoute.Pluginer.AgentRequesting(request, response, agent.Agent, UrlRoute)) { agent.Increment(); if (agent.ValidateRPS()) { if (request.Server.EnableLog(LogType.Debug)) { request.Server.Log(LogType.Debug, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s agent execute!"); } agent.Agent.Execute(request, response, agent, UrlRoute); } else { string error = $"Unable to reach {agent.Agent.Uri} HTTP request, exceeding maximum number of rps limit"; Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response, UrlRoute.Gateway, error, Gateway.SERVER_MAX_OF_RPS); UrlRoute.Gateway.OnResponseError(erea); if (request.Server.EnableLog(LogType.Info)) { request.Server.Log(LogType.Info, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s route server exceeding maximum number of rps limit"); } } } else { if (request.Server.EnableLog(LogType.Info)) { request.Server.Log(LogType.Info, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s route server exceeding cancel"); } } } }
public void Execute(HttpRequest request, HttpResponse response) { if (request.Server.EnableLog(LogType.Debug)) { request.Server.Log(LogType.Debug, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s get urlroute agent!"); } if (!UrlRoute.ValidateRPS()) { string error = $"Unable to reach [{UrlRoute.Url} route {request.Url}] in HTTP request, exceeding maximum number of rps limit"; Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response, UrlRoute.Gateway, error, Gateway.SERVER_MAX_OF_RPS); UrlRoute.Gateway.OnResponseError(erea); if (request.Server.EnableLog(LogType.Info)) { request.Server.Log(LogType.Info, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s route server exceeding maximum number of rps limit"); } return; } var agent = UrlRoute.GetServerAgent(request); if (agent == null) { if (request.Server.EnableLog(LogType.Info)) { request.Server.Log(LogType.Info, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s route server unavailable"); } Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs( request, response, UrlRoute.Gateway, $"The {Url} url route server unavailable", Gateway.URL_NODE_SERVER_UNAVAILABLE); UrlRoute.Gateway.OnResponseError(erea); } else { if (request.Server.EnableLog(LogType.Debug)) { request.Server.Log(LogType.Debug, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s AgentRequesting event!"); } if (UrlRoute.Pluginer.AgentRequesting(request, response, agent.Agent, UrlRoute)) { agent.Increment(); if (agent.ValidateRPS()) { if (request.Server.EnableLog(LogType.Debug)) { request.Server.Log(LogType.Debug, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s agent execute!"); } agent.Agent.Execute(request, response, agent, UrlRoute); } else { string error = $"Unable to reach {agent.Agent.Uri} HTTP request, exceeding maximum number of rps limit"; Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response, UrlRoute.Gateway, error, Gateway.SERVER_MAX_OF_RPS); UrlRoute.Gateway.OnResponseError(erea); if (request.Server.EnableLog(LogType.Info)) { request.Server.Log(LogType.Info, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s route server exceeding maximum number of rps limit"); } } } else { if (request.Server.EnableLog(LogType.Info)) { request.Server.Log(LogType.Info, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} request {UrlRoute.Url}'s route server exceeding cancel"); } } } }