internal HttpRequest CreateRequest(ISession session) { HttpToken token = (HttpToken)session.Tag; token.Request.RequestTime = TimeWatch.GetTotalMilliseconds(); return(token.Request); }
internal void OnCompleted(EventResponseErrorArgs error) { if (System.Threading.Interlocked.CompareExchange(ref mCompletedStatus, 1, 0) == 0) { this.ResponseError = error; Time = (long)(TimeWatch.GetTotalMilliseconds() - Request.RequestTime); mClientAgent.Client.ClientError = null; mClientAgent.Client.DataReceive = null; mClientAgent.Status = TcpClientAgentStatus.ResponseSuccess; //System.Threading.Interlocked.Decrement(ref RequestCount); //mHistoryRequests.Remove(mRequestID, out RequestAgent value); try { if (Code >= 500) { if (Request.Server.EnableLog(BeetleX.EventArgs.LogType.Warring)) { Request.Server.Log(BeetleX.EventArgs.LogType.Warring, $"gateway {Request.ID} {Request.RemoteIPAddress} {Request.Method} {Request.Url} -> {Server.Host}:{Server.Port} completed code {Code} use time:{Time}ms"); } } else { if (Request.Server.EnableLog(BeetleX.EventArgs.LogType.Info)) { Request.Server.Log(BeetleX.EventArgs.LogType.Info, $"gateway {Request.ID} {Request.RemoteIPAddress} {Request.Method} {Request.Url} -> {Server.Host}:{Server.Port} completed code {Code} use time:{Time}ms"); } } if (UrlRoute.Pluginer.RequestedEnabled) { UrlRoute.Pluginer.Requested(this.GetEventRequestCompletedArgs()); } Completed?.Invoke(this); } catch (Exception e_) { if (Request.Server.EnableLog(BeetleX.EventArgs.LogType.Error)) { Request.Server.Log(BeetleX.EventArgs.LogType.Error, $"gateway {Request.ID} {Request.RemoteIPAddress} {Request.Method} {Request.Url} -> {Server.Host}:{Server.Port} completed event error {e_.Message}@{e_.StackTrace}"); } } finally { Request.ClearStream(); if (error != null) { Server.Gateway.OnResponseError(error); } else { Request.Recovery(); } FlushProxyStream(true); Server.Push(mClientAgent); } } }
void IDataResponse.Write(PipeStream stream) { try { OnWrite(stream); } catch (Exception e_) { HttpApiServer server = Request.Server; if (server.EnableLog(EventArgs.LogType.Error)) { server.Log(EventArgs.LogType.Error, $"{Request.RemoteIPAddress} {Request.Method} {Request.Url} response write data error {e_.Message}@{e_.StackTrace}"); Request.Session.Dispose(); } } finally { Request.Server.IncrementResponsed(Request, this, TimeWatch.GetTotalMilliseconds() - Request.RequestTime, int.Parse(this.Code), CodeMsg); Request.Recovery(); } }