eSeGeCe
software
A new feature has been added to Indy Servers, now Server Push is supported by sgcWebSockets library.
HTTP usually works with Request/Response pattern, where client REQUEST a resource to SERVER and SERVER sends a RESPONSE with the resource requested or an error. Usually the client, like a browser, makes a bunch of requests for those assets which are provided by the server.
In the prior screenshot, first client request index.html, server reads this request and sends as a response 2 files: index.html and styles.css, so it avoids a second request to get styles.css
server := TsgcWebSocketHTTPServer.Create(nil);
oLinks := TStringList.Create;
Try
oLinks.Add('/styles.css');
server.PushPromiseAddPreLoadLinks('/index.html', oLinks);
Finally
oLinks.Free;
End;
procedure OnCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo:
TIdHTTPResponseInfo);
begin
if ARequestInfo.Document = '/index.html' then
begin
AResponseInfo.ContentText := '<html></html>';
AResponseInfo.ContentType := 'text/html';
AResponseInfo.ResponseNo := 200;
end
else if ARequestInfo.Document = '/styles.css' then
begin
AResponseInfo.ContentText := '<style></style>';
AResponseInfo.ContentType := 'text/css';
AResponseInfo.ResponseNo := 200;
end;
end;
When the client request /index.html, automatically the server will send the 2 files, index.html and styles.css. You can check this behaviour using google chrome developer tools.
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.