TsgcWebSocketServer_HTTPAPI事件 › OnBeforeForwardHTTP

OnBeforeForwardHTTP 事件

在调度 HTTP 请求之前触发,以便将其转发(反向代理)到另一台 HTTP 服务器。

语法

property OnBeforeForwardHTTP: TsgcWSHTTPAPIBeforeForwardHTTP;
// TsgcWSHTTPAPIBeforeForwardHTTP = procedure(Connection : TsgcWSConnection_HTTPAPI; aRequestInfo: THttpServerRequest; aForward: TsgcWSServerForwardHTTP) of object

默认值

备注

OnBeforeForwardHTTP 针对通过 HTTP.SYS 接收的每个 HTTP 请求触发,允许服务器充当特定端点的反向代理。检查 aRequestInfo.Document 以决定是否需要转发请求;若需要,请将 aForward.Enabled 设置为 True 并将 aForward.URL 指向目标服务器。aForward 对象上的其他属性可微调转发请求:Document(覆盖目标路径)、QueryParams、Host、Origin、CustomHeaders、LogFilename、NoCache 以及针对 HTTPS 目标的 TLSOptions。当 aForward.Enabled 保持 False 时,请求将通过 OnHTTPRequest 在本地正常处理。

示例


procedure OnBeforeForwardHTTP(Connection: TsgcWSConnection_HTTPAPI;
  aRequestInfo: THttpServerRequest; aForward: TsgcWSServerForwardHTTP);
begin
  if aRequestInfo.Document = '/internal' then
  begin
    aForward.Enabled := True;
    aForward.URL := 'http://localhost:8080';
  end;
end;

返回事件