TsgcWebSocketServer_HTTPAPIEvents › OnBeforeForwardHTTP

OnBeforeForwardHTTP Event

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

Syntax

public event TsgcWSHTTPAPIBeforeForwardHTTPHandler OnBeforeForwardHTTP;
// delegate void TsgcWSHTTPAPIBeforeForwardHTTPHandler(TsgcWSConnection_HTTPAPI Connection, THttpServerRequest aRequestInfo, TsgcWSServerForwardHTTP aForward)

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


void OnBeforeForwardHTTP(TsgcWSConnection_HTTPAPI Connection,
  THttpServerRequest aRequestInfo, TsgcWSServerForwardHTTP aForward)
{
  if (aRequestInfo.Document == "/internal")
  {
    aForward.Enabled = true;
    aForward.URL = "http://localhost:8080";
  }
}

Back to Events