TsgcHTTP2Client › 事件 › OnHTTP2ResponseFragment
当 FragmentedData 以流式方式传递数据时,每个流式响应片段触发一次此事件。
property OnHTTP2ResponseFragment: TsgcHTTP2ClientResponseFragmentEvent;
// TsgcHTTP2ClientResponseFragmentEvent = procedure(Sender: TObject; const Connection: TsgcHTTP2ConnectionClient; const Request: TsgcHTTP2RequestProperty; const Fragment: TsgcHTTP2ResponseFragmentProperty) of object
—
每当收到部分响应数据包时,OnHTTP2ResponseFragment 就会触发,从而可以在字节到达时立即处理流,而无需等待完整负载。通常用于长连接或分块 HTTP/2 流(例如事件流或时钟流式端点),通过将 FragmentedData 设置为 h2fdAll(最后一个数据包到达时也触发 OnHTTP2Response)或 h2fdOnlyFragmented(仅分发此事件)来启用。Fragment 参数通过 Data、DataString 和 DataUTF8 公开部分负载;Request 参数标识发起该请求的源请求。
oClient := TsgcHTTP2Client.Create(nil);
oClient.OnHTTP2ResponseFragment := OnHTTP2ResponseFragmentEvent;
oClient.Get('https://http2.golang.org/clockstream');
procedure OnHTTP2ResponseFragmentEvent(Sender: TObject; const Connection: TsgcHTTP2ConnectionClient;
const Request: TsgcHTTP2RequestProperty; const Fragment: TsgcHTTP2ResponseFragmentProperty);
begin
ShowMessage(Fragment.DataString);
end;