Delphi TIdHttpServer:是否可以记录所有流量?

Delphi TIdHttpServer:是否可以记录所有流量?,http,delphi,indy,Http,Delphi,Indy,我正在编写一个带有TIdHttpServer的HTTP服务器,我希望正确记录所有流量(完整HTTP请求)。我为此找到了几个类似的主题,但没有一个能够保证响应是否确实发送。 我知道Indy中的函数TIdCustomHTTPServer.DoExecute(AContext:TIdContext):boolean会触发异常如果无法发送响应,但该异常也可能在发送响应后发生(并且TIdHttpServer正在等待下一个命令)。 有没有办法知道命令是否真的被发送了 在下面的示例中,我成功地正确记录了传入的

我正在编写一个带有TIdHttpServer的HTTP服务器,我希望正确记录所有流量(完整HTTP请求)。我为此找到了几个类似的主题,但没有一个能够保证响应是否确实发送。
我知道Indy中的
函数TIdCustomHTTPServer.DoExecute(AContext:TIdContext):boolean会触发异常
如果无法发送响应,但该异常也可能在发送响应后发生(并且TIdHttpServer正在等待下一个命令)。 有没有办法知道命令是否真的被发送了

在下面的示例中,我成功地正确记录了传入的消息,但没有找到正确的方法来检测响应是否已发送

procedure TfmMain.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
  //log the incoming request
  Log(getIdConnPeerAsStr(AContext) {IP:port} + (ARequestInfo.RawHTTPCommand + ARequestInfo.RawHeaders.Text));

  //Prepare the response
  AResponseInfo.ContentType := 'text/html';
  AResponseInfo.CharSet := 'utf-8';
  AResponseInfo.ContentText := '<html><body>Hello</body></html>';

  //How to log the output(AResponseInfo) here?  It is too soon because the sending of the packet has not yet occurred
end;
procedure TfmMain.IdHTTPServer1CommandGet(AContext:TIdContext;ARequestInfo:TIdHTTPRequestInfo;AResponseInfo:TIdHTTPResponseInfo);
开始
//记录传入的请求
日志(getidconnpeerastr(AContext){IP:port}+(ARequestInfo.RawHTTPCommand+ARequestInfo.RawHeaders.Text));
//准备答复
AResponseInfo.ContentType:=“文本/html”;
AResponseInfo.CharSet:=“utf-8”;
AResponseInfo.ContentText:=“你好”;
//如何在此处记录输出(AresOnSeInfo)?时间太早,因为尚未发送数据包
结束;

Indy包含可用于记录低级数据流的TIdIntercept*类,只需创建一个类并将其分配给服务器的intercept属性,例如TIdInterceptSimLog(记录到文件)还有几个同样是intercepts的
TIdLog…
组件。但是,在任何情况下,请注意,拦截都是为每个连接分配的,虽然服务器确实有一个
拦截
属性来帮助自动创建客户端连接拦截,但大多数拦截组件(包括
tidsinterceptsimlog
)实际上并没有实现服务器端支持,因此,它们不能与服务器的
Intercept
属性一起使用。它们必须在运行时手动创建并分配给服务器的
OnConnect
事件中的
AContext.Connection.Intercept
属性。