TsgcWebSocketHTTPServerEvents › OnAfterForwardHTTP

OnAfterForwardHTTP Event

Fires after an HTTP request has been forwarded so the application can inspect the result or an error returned by the upstream server.

Syntax

public event TsgcWSOnAfterForwardHTTPHandler OnAfterForwardHTTP;
// delegate void TsgcWSOnAfterForwardHTTPHandler(TsgcWSConnection Connection, TIdHTTPRequestInfo ARequestInfo, TIdHTTPResponseInfo AResponseInfo, Exception E)

Default Value

Remarks

OnAfterForwardHTTP is raised once OnBeforeForwardHTTP has enabled forwarding and the upstream HTTP request has completed. ARequestInfo is the original client request, AResponseInfo is the response about to be written back (ResponseNo, ContentType, ContentText...) as populated from the upstream server, and E is either nil on success or the exception raised while contacting the target server. Use the event to log the outcome, rewrite response headers/body before they are returned to the client, or override the response with a custom error page when the upstream call failed.

Example


void OnAfterForwardHTTP(TsgcWSConnection Connection, TsgcWSHTTPRequestInfo ARequestInfo,
  TsgcWSHTTPResponseInfo AResponseInfo, Exception E)
{
  if (E != null)
  {
    AResponseInfo.ResponseNo = 502;
    AResponseInfo.ContentText = "Upstream error: " + E.Message;
  }
  else
    Console.WriteLine("forwarded " + ARequestInfo.Document + " -> " + AResponseInfo.ResponseNo);
}

Back to Events