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.
property OnAfterForwardHTTP: TsgcWSHTTPAPIAfterForwardHTTP;
// TsgcWSHTTPAPIAfterForwardHTTP = procedure(Connection: TsgcWSConnection; aRequestInfo: THttpServerRequest; var aResponseInfo: THttpServerResponse; E: Exception) of object
—
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.
procedure OnAfterForwardHTTP(Connection: TsgcWSConnection;
aRequestInfo: THttpServerRequest; var aResponseInfo: THttpServerResponse;
E: Exception);
begin
if Assigned(E) then
begin
aResponseInfo.ResponseNo := 502;
aResponseInfo.ContentText := 'Upstream error: ' + E.Message;
end
else
Log(Format('forwarded %s -> %d', [aRequestInfo.Document, aResponseInfo.ResponseNo]));
end;