TsgcWebSocketHTTPServer › Properties › HTTPCompression
Compresses HTTP/1.1 responses with gzip or deflate when the client advertises support, for both DocumentRoot static files and dynamic OnCommandGet responses.
property HTTPCompression: TsgcHTTPCompression_Options read FHTTPCompression write SetHTTPCompression;
Enabled=False
By default the server sends every HTTP/1.1 response uncompressed. Set HTTPCompression.Enabled to True to compress eligible responses with gzip or deflate whenever the client's Accept-Encoding request header allows it. Level is the compression level from 0 to 9 (default 6). MinSize skips compressing responses smaller than this many bytes (default 1,024), since compressing a tiny body rarely pays for the CPU cost. Algorithms is the set of encodings the server may use (default both caGZip and caDeflate; gzip is preferred when the client accepts both). ContentTypes lists which response content types are eligible, wildcards such as text/* are supported, and it defaults to the common text, JSON, JavaScript, XML and SVG types.
The server never compresses a response that already has a Content-Encoding header, a 204/304/1xx status code, or a text/event-stream (Server-Sent Events) content type, and it skips compression when the compressed result would not actually be smaller. When it compresses a response it sets Content-Encoding and adds a Vary: Accept-Encoding header. This property covers HTTP/1.1 responses only; HTTP/2 responses are not affected. See HTTP Compression for a full explanation and how it differs from WebSocket message compression.
oServer := TsgcWebSocketHTTPServer.Create(nil);
oServer.DocumentRoot := 'C:\inetpub\wwwroot';
oServer.HTTPCompression.Enabled := true;
oServer.HTTPCompression.MinSize := 1024;
oServer.Active := true;