TsgcWebSocketHTTPServerMethods › PushPromiseAddPreLoadLinks

PushPromiseAddPreLoadLinks Method

Registers an HTTP/2 Server Push rule that preloads a set of related resources whenever a matching request path is served.

Syntax

public void PushPromiseAddPreLoadLinks(string aPathMatch, TStrings aLinks);

Parameters

NameTypeDescription
aPathMatchconst StringRequest path that triggers the push, for example /index.html. When a client requests this resource over HTTP/2 the server also pushes the links registered for it.
aLinksconst TStringsList of resource paths (one per line) that will be pushed alongside the matched request, such as stylesheets, scripts or images referenced by the primary document.

Remarks

PushPromiseAddPreLoadLinks appends a new entry to the internal HTTP/2 push-promise table. Whenever an HTTP/2 client requests the path given by aPathMatch, the server emits a PUSH_PROMISE frame for every link in aLinks before the main response so the client can populate its cache without issuing extra round-trips; see HTTP/2 Server Push for the full workflow. The link list is copied, so the caller is free to free the supplied TStrings after the call. Push promise is only honoured on HTTP/2 connections negotiated via ALPN; HTTP/1.1 clients receive the main response without the promised resources. Call PushPromiseRemovePreLoadLinks to drop the rule.

Example


TsgcWebSocketHTTPServer oServer = new TsgcWebSocketHTTPServer(this);
oServer.PushPromiseAddPreLoadLinks("/index.html", "/styles.css");

Back to Methods