TsgcWebSocketServer_HTTPAPI › イベント › OnAfterForwardHTTP
HTTPリクエストが転送された後に発生し、アプリケーションが結果や上流サーバーから返されたエラーを検査できるようにします。
property OnAfterForwardHTTP: TsgcWSHTTPAPIAfterForwardHTTP;
// TsgcWSHTTPAPIAfterForwardHTTP = procedure(Connection: TsgcWSConnection; aRequestInfo: THttpServerRequest; var aResponseInfo: THttpServerResponse; E: Exception) of object
—
OnAfterForwardHTTP は、OnBeforeForwardHTTP が転送を有効にしてアップストリームの HTTP リクエストが完了した後に発生します。aRequestInfo は元のクライアントリクエスト、aResponseInfo はアップストリームサーバーから設定された(ResponseNo、ContentType、ContentText...)クライアントに返す直前のレスポンス、E は成功時は nil、ターゲットサーバーへの接続中に発生した例外です。このイベントを使用して結果をログに記録したり、クライアントに返す前にレスポンスヘッダー/ボディを書き換えたり、アップストリームの呼び出しが失敗した場合にカスタムエラーページでレスポンスを上書きしたりできます。
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;