TsgcWebSocketHTTPServerEvents › OnBeforeForwardHTTP

OnBeforeForwardHTTP Event

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

Syntax

public event TsgcWSOnBeforeForwardHTTPHandler OnBeforeForwardHTTP;
// delegate void TsgcWSOnBeforeForwardHTTPHandler(TsgcWSConnection Connection, TIdHTTPRequestInfo ARequestInfo, TsgcWSServerForwardHTTP aForward)

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


void OnBeforeForwardHTTP(TsgcWSConnection Connection, TsgcWSHTTPRequestInfo ARequestInfo,
  ref TsgcWSServerForwardHTTP aForward)
{
  if (ARequestInfo.Document == "/internal")
  {
    aForward.Enabled = true;
    aForward.URL = "http://localhost:8080";
  }
}

Back to Events