Supportato da
HTTPCompression compresses HTTP/1.1 responses with gzip or deflate before they are sent to the client, when the client advertises support for it using the Accept-Encoding request header. It applies both to static files served from DocumentRoot and to responses you build yourself in OnCommandGet. It is disabled by default, so existing applications are not affected until you turn it on.
This is a different feature from Compression, which compresses WebSocket messages using the PerMessage_Deflate protocol. HTTPCompression only affects plain HTTP/1.1 requests and responses; it has no effect on WebSocket traffic, and Compression has no effect on HTTP responses.
To enable it, set:
HTTPCompression / Enabled
You can also tune it:
Level — compression level from 0 (none) to 9 (maximum); default 6.
MinSize — responses smaller than this, in bytes, are not compressed; default 1024.
Algorithms — which encodings the server is allowed to use; default both gzip and deflate. When the client accepts both, gzip is preferred.
ContentTypes — list of content types that are eligible for compression, wildcards like "text/*" are supported; defaults to the common text, JSON, JavaScript, XML and SVG types.
Il server negozia la codifica in base all'header Accept-Encoding della richiesta, considerando un valore di qualità pari a 0 come un rifiuto (ad esempio "gzip;q=0"). Non comprime mai una risposta che ha già un Content-Encoding, uno stato 204/304/1xx, uno stream Server-Sent Events, o un corpo che non risulterebbe più piccolo. Quando comprime, imposta l'header Content-Encoding della risposta e aggiunge Vary: Accept-Encoding, così le cache indicizzano correttamente in base alla codifica.
HTTPCompression currently applies to HTTP/1.1 responses only; HTTP/2 responses are not compressed by this property. If you compress content that mixes a secret (such as a CSRF token) with attacker-influenced data over a TLS connection, be aware that response compression is what makes the BREACH class of attack possible; this is a general property of HTTP compression, not something specific to this implementation.
oServer := TsgcWebSocketHTTPServer.Create(nil);
oServer.DocumentRoot := 'C:\inetpub\wwwroot';
oServer.HTTPCompression.Enabled := true;
oServer.HTTPCompression.MinSize := 1024;
oServer.Active := true;