TsgcWebSocketServer_HTTPAPI › Events › OnAfterForwardHTTP
Fires after an HTTP request has been forwarded so the application can inspect the result or an error returned by the upstream server.
public event TsgcWSHTTPAPIAfterForwardHTTPHandler OnAfterForwardHTTP;
// delegate void TsgcWSHTTPAPIAfterForwardHTTPHandler(TsgcWSConnection Connection, THttpServerRequest aRequestInfo, out THttpServerResponse aResponseInfo, Exception E)
—
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 to the client (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.
void OnAfterForwardHTTP(TsgcWSConnection Connection,
THttpServerRequest aRequestInfo, ref THttpServerResponse aResponseInfo,
Exception E)
{
if (E != null)
{
aResponseInfo.ResponseNo = 502;
aResponseInfo.ContentText = "Upstream error: " + E.Message;
}
else
Console.WriteLine("forwarded " + aRequestInfo.Document + " -> " + aResponseInfo.ResponseNo);
}