リクエスト | HTTP/2 サーバープッシュ

サーバープッシュは、単一のクライアントリクエストに対してサーバーが複数のレスポンスを送信する機能です。つまり、元のリクエストへのレスポンスに加えて、サーバーはクライアントが明示的にリクエストしなくても追加のリソースをプッシュできます。

 

 

サーバーがクライアントにPushPromiseメッセージを送信するたびに、OnHTTP2PushPromise イベントが呼び出されます。クライアントがPushPromiseを受信すると、サーバーが次のパケットでこのリソースを送信することを意味するため、クライアントはそれを受け入れるか拒否できます。

 


oClient := TsgcHTTP2Client.Create(nil);
oClient.OnHTTP2PushPromise := OnHTTP2PushPromiseEvent;
oClient.Get('https://http2.golang.org/serverpush');
...
procedure OnHTTP2PushPromiseEvent(Sender: TObject; const Connection: TsgcHTTP2ConnectionClient; 
  const PushPromise: TsgcHTTP2_Frame_PushPromise; var Cancel: Boolean);
begin
  if PushPromise.URL = '/serverpush/static/godocs.js' then
    Cancel := True
  else
    Cancel := False;
end;