TsgcWebSocketHTTPServerEventi › OnBeforeForwardHTTP

OnBeforeForwardHTTP Evento

Si attiva prima che una richiesta HTTP venga inviata, in modo da poterla inoltrare (reverse-proxy) a un altro server HTTP.

Sintassi

property OnBeforeForwardHTTP: TsgcWSOnBeforeForwardHTTP;
// TsgcWSOnBeforeForwardHTTP = procedure(Connection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; aForward: TsgcWSServerForwardHTTP) of object

Valore predefinito

Note

OnBeforeForwardHTTP viene generato per ogni richiesta HTTP e consente al server di agire come proxy inverso per gli endpoint selezionati. Ispezionare ARequestInfo.Document per decidere se la richiesta deve essere inoltrata; in tal caso, impostare aForward.Enabled su True e assegnare aForward.URL al server di destinazione. Le proprietà aggiuntive sull'oggetto aForward consentono di ottimizzare la richiesta inoltrata: Document (sovrascrive il percorso di destinazione), QueryParams, Host, Origin, CustomHeaders, LogFilename, NoCache e TLSOptions per destinazioni HTTPS. Quando aForward.Enabled rimane False, la richiesta viene servita localmente tramite OnCommandGet/OnCommandOther come di consueto.

Esempio


procedure OnBeforeForwardHTTP(Connection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo;
  aForward: TsgcWSServerForwardHTTP);
begin
  if ARequestInfo.Document = '/internal' then
  begin
    aForward.Enabled := True;
    aForward.URL := 'http://localhost:8080';
  end;
end;

Torna agli Eventi