TsgcHTTP2Client | Descarga de archivos HTTP/2

Cuando el cliente solicita un archivo al servidor, utilice el evento OnHTTP2Response para cargar la respuesta en flujo.

 

Descargas de archivos grandes

Al descargar archivos grandes (cientos de MB o más), establezca HTTP2Options.ReadTimeout en 0 (sin tiempo de espera) para garantizar que la transferencia se complete sin ser interrumpida por el tiempo de espera predeterminado de 60 segundos:

 


oClient := TsgcHTTP2Client.Create(nil);
oClient.HTTP2Options.ReadTimeout := 0; // no timeout for large files
oClient.Get('https://server/largefile', oStream);

 


oClient := TsgcHTTP2Client.Create(nil);
oClient.OnHTTP2Response := OnHTTP2ResponseEvent;
oClient.Get('https://http2.golang.org/file/gopher.png');
...
procedure OnHTTP2ResponseEventEvent(Sender: TObject; const Connection: TsgcHTTP2ConnectionClient; 
  const Request: TsgcHTTP2RequestProperty; const Response: TsgcHTTP2ResponseProperty)
begin
  oStream := TFileStream.Create('file', fmOpenWrite or fmCreate);
  Try
    oStream.CopyFrom(Response.Data, Response.Data.Size);
  Finally
    oStream.Free;
  End;
end;