Example #1
0
        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}");
                }
            }
        }
Example #2
0
 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();
     }
 }