TsgcWebSocketLoadBalancerServer › Events › OnLoadBalancerHTTPResponse
Fires after the load balancer receives the HTTP response from the backend and before it is returned to the downstream client.
property OnLoadBalancerHTTPResponse: TsgcWSLBHTTPResponseEvent;
// TsgcWSLBHTTPResponseEvent = procedure(Sender: TObject; Connection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; E: Exception) of object
—
OnLoadBalancerHTTPResponse is raised once the backend has answered a forwarded HTTP request, or when the forwarding failed. ARequestInfo is the original request and AResponseInfo carries the response from the backend (ResponseNo, ContentText/ContentStream, custom headers) that can still be mutated before it is written back to the downstream client. E is the exception raised during forwarding (nil when the exchange succeeded); when E is assigned you can build a custom error response by setting AResponseInfo fields. Typical uses are adding security response headers, rewriting Location headers for reverse-proxy scenarios, gathering latency metrics, or turning a backend failure into a custom HTTP 502 page.
procedure OnLoadBalancerHTTPResponse(Sender: TObject; Connection: TsgcWSConnection;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; E: Exception);
begin
if Assigned(E) then
begin
AResponseInfo.ResponseNo := 502;
AResponseInfo.ContentText := 'Backend unavailable: ' + E.Message;
end
else
AResponseInfo.CustomHeaders.Add('X-LoadBalancer: sgcWebSockets');
end;