/// <summary> /// A request was received from the parser. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnRequest(object sender, FactoryRequestEventArgs e) { _context = this; var response = HttpFactory.Current.Get <IResponse>(this, e.Request); _logger.Debug("Received '" + e.Request.Method + " " + e.Request.Uri.PathAndQuery + "' from " + Socket.RemoteEndPoint); // keep alive. if (e.Request.Connection != null && e.Request.Connection.Type == ConnectionType.KeepAlive) { response.Add(new StringHeader("Keep-Alive", "timeout=5, max=100")); // refresh timer if (_keepAlive != null) { _keepAlive.Change(_keepAliveTimeout, _keepAliveTimeout); } } CurrentRequestReceived(this, new RequestEventArgs(this, e.Request, response)); RequestReceived(this, new RequestEventArgs(this, e.Request, response)); // if (response.Connection.Type == ConnectionType.KeepAlive) { if (_keepAlive == null) { _keepAlive = new Timer(OnConnectionTimeout, null, _keepAliveTimeout, _keepAliveTimeout); } } RequestCompleted(this, new RequestEventArgs(this, e.Request, response)); CurrentRequestCompleted(this, new RequestEventArgs(this, e.Request, response)); }
/// <summary> /// A request was received from the parser. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnRequest(object sender, FactoryRequestEventArgs e) { _context = this; Response = HttpFactory.Current.Get <IResponse>(this, e.Request); _logger.Debug("Received '" + e.Request.Method + " " + e.Request.Uri.PathAndQuery + "' from " + Socket.RemoteEndPoint); LastAction = DateTime.Now; // keep alive. if (e.Request.Connection != null && e.Request.Connection.Type == ConnectionType.KeepAlive) { Response.Add(new StringHeader("Keep-Alive", "timeout=5, max=" + HTTPContextManager.MAX_KEEPALIVE)); } Request = e.Request; CurrentRequestReceived(this, new RequestEventArgs(this, e.Request, Response)); RequestReceived(this, new RequestEventArgs(this, e.Request, Response)); if (Response.Connection.Type == ConnectionType.KeepAlive) { HTTPContextManager.Register(this); } RequestCompleted(this, new RequestEventArgs(this, e.Request, Response)); CurrentRequestCompleted(this, new RequestEventArgs(this, e.Request, Response)); }
/// <summary> /// 消息解析器解析出一个请求消息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnRequest(object sender, FactoryRequestEventArgs e) { _context = this; // 根据请求消息内容生成响应消息 Response = HttpFactory.Current.Get <IResponse>(this, e.Request); Logger.Debug("Received '" + e.Request.Method + " " + e.Request.Uri.PathAndQuery + "' from " + Socket.RemoteEndPoint); // 如果请求连接中设置了保活 if (e.Request.Connection != null && e.Request.Connection.Type == ConnectionType.KeepAlive) { Response.Add(new StringHeader("Keep-Alive", "timeout=5, max=100")); // 刷新计时器 if (_keepAlive != null) { _keepAlive.Change(_keepAliveTimeout, _keepAliveTimeout); } } // 记录请求消息 Request = e.Request; // 通知处理请求 CurrentRequestReceived(this, new RequestEventArgs(this, e.Request, Response)); RequestReceived(this, new RequestEventArgs(this, e.Request, Response)); // 如果请求连接中设置了保活,记录请求处理的超时时间 if (Response.Connection.Type == ConnectionType.KeepAlive) { if (_keepAlive == null) { _keepAlive = new Timer(OnKeepAliveTimeout, null, _keepAliveTimeout, _keepAliveTimeout); } } // 通知请求处理完毕 RequestCompleted(this, new RequestEventArgs(this, e.Request, Response)); CurrentRequestCompleted(this, new RequestEventArgs(this, e.Request, Response)); }