Requests | HTTP/2 Server Push

Server Push is the ability of the server to send multiple responses for a single client request. That is, in addition to the response to the original request, the server can push additional resources to the client, without the client having to request each one explicitly.

 

 

Every time server sends to client a PushPromise message, OnHTTP2PushPromise event is called. When client receives a PushPromise, means that server will send in the next packets this resource, so client can accepts or not this.

 


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;