요청 | HTTP/2 Server Push

Server Push는 단일 클라이언트 요청에 대해 서버가 여러 응답을 보낼 수 있는 기능입니다. 즉, 원래 요청에 대한 응답 외에도, 서버는 클라이언트가 각각을 명시적으로 요청하지 않고도 추가 리소스를 클라이언트에 푸시할 수 있습니다.

 

 

서버가 클라이언트에 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;