HTTP 압축

지원하는 항목

TsgcWebSocketHTTPServer

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.

이를 활성화하려면 다음과 같이 설정하십시오:

HTTPCompression / Enabled

You can also tune it:

Level — compression level from 0 (none) to 9 (maximum); default 6.

MinSize — 바이트 단위로 이 값보다 작은 응답은 압축되지 않습니다. 기본값은 1024입니다.

Algorithms — 서버가 사용할 수 있는 인코딩을 지정하며, 기본값은 gzip과 deflate 모두입니다. 클라이언트가 둘 다 허용하면 gzip이 우선됩니다.

ContentTypes — 압축 대상이 될 수 있는 콘텐츠 타입 목록입니다. "text/*"와 같은 와일드카드도 지원되며, 기본값은 일반적인 text, JSON, JavaScript, XML, SVG 타입입니다.

The server negotiates the encoding from the request's Accept-Encoding header, honoring a quality value of 0 as a refusal (for example "gzip;q=0"). It never compresses a response that already has a Content-Encoding, a 204/304/1xx status, a Server-Sent Events stream, or a body that would not end up smaller. When it does compress, it sets the response's Content-Encoding header and adds Vary: Accept-Encoding so caches key on the encoding correctly.

HTTPCompression은 현재 HTTP/1.1 응답에만 적용되며, HTTP/2 응답은 이 속성으로 압축되지 않습니다. TLS 연결을 통해 비밀 값(예: CSRF 토큰)과 공격자가 영향을 미칠 수 있는 데이터가 혼합된 콘텐츠를 압축하는 경우, 응답 압축이 BREACH 계열 공격을 가능하게 하는 요인이라는 점에 유의하십시오. 이는 이 구현에 특화된 것이 아니라 HTTP 압축 일반의 특성입니다.


oServer := TsgcWebSocketHTTPServer.Create(nil);
oServer.DocumentRoot := 'C:\inetpub\wwwroot';
oServer.HTTPCompression.Enabled := true;
oServer.HTTPCompression.MinSize := 1024;
oServer.Active := true;