TsgcWebSocketServer_HTTPAPIEvents › OnBeforeForwardHTTP

OnBeforeForwardHTTP Event

Fires before an HTTP request is dispatched so it can be forwarded (reverse-proxied) to another HTTP server.

Syntax

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

Default Value

Remarks

OnBeforeForwardHTTP is raised for every HTTP request received through HTTP.SYS and lets the server act as a reverse proxy for selected endpoints. Inspect aRequestInfo.Document to decide whether the request must be forwarded; when it must, set aForward.Enabled to True and assign aForward.URL to the target server. Additional properties on the aForward object fine-tune the forwarded request: Document (override the target path), QueryParams, Host, Origin, CustomHeaders, LogFilename, NoCache and TLSOptions for HTTPS targets. When aForward.Enabled stays False the request is served locally through OnHTTPRequest as usual.

Example


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;

Back to Events