public async void Execute(HttpRequest request, HttpResponse response, UrlRouteServerGroup.UrlServerInfo serverInfo, Routes.UrlRoute urlRoute) { try { var clientAgent = await PopClient(); if (clientAgent == null) { string error = $"Unable to reach {Host}:{Port} HTTP request, exceeding maximum number of connections"; Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response, Gateway, error, Gateway.SERVER_MAX_OF_CONNECTIONS); Gateway.OnResponseError(erea); } else { RequestAgent agent = new RequestAgent(clientAgent, this, request, response, serverInfo, urlRoute); agent.Completed = OnCompleted; Gateway.AddRequest(agent); //agent.Execute(); } } catch (Exception e_) { if (urlRoute.Gateway.HttpServer.EnableLog(LogType.Error)) { urlRoute.Gateway.HttpServer.Log(LogType.Error, $"gateway {request.Url} route to {Uri} error {e_.Message}{e_.StackTrace}"); } } }
public async void Execute(HttpRequest request, HttpResponse response, UrlRouteServerGroup.UrlServerInfo serverInfo, Routes.UrlRoute urlRoute) { try { var clientAgent = await PopClient(); if (clientAgent == null) { string error = $"Unable to reach {Host}:{Port} request queue overflow!"; Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response, Gateway, error, Gateway.SERVER_AGENT_QUEUE_OVERFLOW); Gateway.OnResponseError(erea); if (request.Server.EnableLog(LogType.Info)) { request.Server.Log(LogType.Info, $"Gateway {request.ID} {request.RemoteIPAddress} {request.Method} {request.Url} route to {Uri} error exceeding maximum number of connections"); } } else { clientAgent.Status = TcpClientAgentStatus.None; RequestAgent agent = new RequestAgent(clientAgent, this, request, response, serverInfo, urlRoute); agent.Completed = OnCompleted; agent.Execute(); } } catch (Exception e_) { if (urlRoute.Gateway.HttpServer.EnableLog(LogType.Error)) { urlRoute.Gateway.HttpServer.Log(LogType.Error, $"Gateway {request.RemoteIPAddress} {request.Method} {request.Url} route to {Uri} error {e_.Message}{e_.StackTrace}"); } } }
public void Execute(HttpRequest request, HttpResponse response) { if (ExecuteFilter(request, response)) { var agent = UrlRoute.GetServerAgent(request); if (agent == null) { 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 (UrlRoute.Gateway.OnAgentRequesting(request, response, agent.Agent, UrlRoute)) { agent.Increment(); if (agent.ValidateRPS()) { agent.Agent.Execute(request, response, agent, UrlRoute); } else { string error = $"Unable to reach {agent.Agent.Uri} HTTP request, exceeding maximum number of RPS"; Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response, UrlRoute.Gateway, error, Gateway.SERVER_MAX_OF_RPS); UrlRoute.Gateway.OnResponseError(erea); } } } } }
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!"); } 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"; 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"); } } } 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 (ExecuteFilter(request, response)) { var agent = UrlRoute.GetServerAgent(request); if (agent == null) { BadGateway result = new BadGateway($"The {Url} url route server unavailable"); Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs( request, response, result, BadGateway.URL_NODE_SERVER_UNAVAILABLE); UrlRoute.Gateway.OnResponseError(erea); } else { agent.Execute(request, response); } } }
public void Execute(HttpRequest request, HttpResponse response) { TcpClientAgent clientAgent = PopClient(); if (clientAgent == null) { string error = $"Unable to reach {Host}:{Port} HTTP request, exceeding maximum number of connections"; if (Gateway.HttpServer.EnableLog(LogType.Error)) { Gateway.HttpServer.Log(LogType.Error, error); } BadGateway result = new BadGateway(error); Events.EventResponseErrorArgs erea = new Events.EventResponseErrorArgs(request, response, result, BadGateway.SERVER_MAX_OF_CONNECTIONS); Gateway.OnResponseError(erea); } else { RequestAgent agent = new RequestAgent(clientAgent, this, request, response); agent.Completed = OnCompleted; agent.Execute(); } }
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"); } } } }