TsgcWebSocketHTTPServerEvents › OnBeforeForwardHTTP

OnBeforeForwardHTTP Event

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

Syntax

property OnBeforeForwardHTTP: TsgcWSOnBeforeForwardHTTP;
// TsgcWSOnBeforeForwardHTTP = procedure(Connection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; aForward: TsgcWSServerForwardHTTP) of object

Default Value

Remarks

OnBeforeForwardHTTP is raised for every HTTP request 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 OnCommandGet/OnCommandOther as usual.

Example


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

Back to Events