|Response status codes|
|Security access control methods|
HTTP compression is a capability that can be built into
HTTP data is compressed before it is sent from the server: compliant browsers will announce what methods are supported to the server before downloading the correct format; browsers that do not support compliant compression method will download uncompressed data. The most common compression schemes include gzip and Brotli; a full list of available schemes is maintained by the IANA.
There are two different ways compression can be done in HTTP. At a lower level, a Transfer-Encoding header field may indicate the payload of an HTTP message is compressed. At a higher level, a Content-Encoding header field may indicate that a resource being transferred, cached, or otherwise referenced is compressed. Compression using Content-Encoding is more widely supported than Transfer-Encoding, and some browsers do not advertise support for Transfer-Encoding compression to avoid triggering bugs in servers.
Compression scheme negotiation
The negotiation is done in two steps, described in RFC 2616 and RFC 9110:
GET /encrypted-area HTTP/1.1 Host: www.example.com Accept-Encoding: gzip, deflate
2. If the server supports one or more compression schemes, the outgoing data may be compressed by one or more methods supported by both parties. If this is the case, the server will add a Content-Encoding or Transfer-Encoding field in the HTTP response with the used schemes, separated by commas.
HTTP/1.1 200 OK Date: mon, 26 June 2016 22:38:34 GMT Server: Apache/220.127.116.11 (Unix) (Red-Hat/Linux) Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT Accept-Ranges: bytes Content-Length: 438 Connection: close Content-Type: text/html; charset=UTF-8 Content-Encoding: gzip
The web server is by no means obligated to use any compression method – this depends on the internal settings of the web server and also may depend on the internal architecture of the website in question.
The official list of tokens available to servers and client is maintained by IANA, and it includes:
- br – Brotli, a compression algorithm specifically designed for HTTP content encoding, defined in RFC 7932 and implemented in all modern major browsers.
- compress– UNIX "compress" program method (historic; deprecated in most applications and replaced by gzip or deflate)
- deflate – compression based on the
- exi – W3C Efficient XML Interchange
- deflate algorithm for compression, but the data format and the checksum algorithm differ from the "deflate" content-encoding. This method is the most broadly supported as of March 2011.
- identity – No transformation is used. This is the default value for content coding.
- pack200-gzip – Network Transfer Format for Java Archives
- zstd – Zstandard compression, defined in RFC 8478
In addition to these, a number of unofficial or non-standardized tokens are used in the wild by either servers or clients:
- bzip2 – compression based on the free bzip2 format, supported by lighttpd
- lzma – compression based on (raw) LZMA is available in Opera 20, and in elinks via a compile-time option
- peerdist – Microsoft Peer Content Caching and Retrieval
- rsync – delta encoding in HTTP, implemented by a pair of rproxy proxies.
- xpress – Microsoft compression protocol used by Windows 8 and later for Windows Store application updates. LZ77-based compression optionally using a Huffman encoding.
- xz – LZMA2-based content compression, supported by a non-official Firefox patch; and fully implemented in mget since 2013-12-31.
Servers that support HTTP compression
- SAP NetWeaver
- Microsoft IIS: built-in or using third-party module
- Apache HTTP Server, via mod_deflate (despite its name, only supporting gzip), and mod_brotli
- Hiawatha HTTP server: serves pre-compressed files
- Cherokee HTTP server, On the fly gzip and deflate compressions
- Oracle iPlanet Web Server
- Zeus Web Server
- nginx – built-in
- Applications based on Tornado, if "compress_response" is set to True in the application settings (for versions prior to 4.0, set "gzip" to True)
- Jetty Server– built-into default static content serving and available via servlet filter configurations
- Apache Tomcat
- IBM Websphere
- Ruby Rack, via the Rack::Deflater middleware
- Varnish – built-in. Works also with ESI
- Armeria – Serving pre-compressed files
- NaviServer – built-in, dynamic and static compression
Many content delivery networks also implement HTTP compression to improve speedy delivery of resources to end users.
Various online tools exist to verify a working implementation of HTTP compression. These online tools usually request multiple variants of a URL, each with different request headers (with varying Accept-Encoding content). HTTP compression is considered to be implemented correctly when the server returns a document in a compressed format. By comparing the sizes of the returned documents, the effective compression ratio can be calculated (even between different compression algorithms).
Problems preventing the use of HTTP compression
A 2009 article by Google engineers Arvind Jain and Jason Glasgow states that more than 99 person-years are wasted daily due to increase in page load time when users do not receive compressed content. This occurs when anti-virus software interferes with connections to force them to be uncompressed, where proxies are used (with overcautious web browsers), where servers are misconfigured, and where browser bugs stop compression being used. Internet Explorer 6, which drops to HTTP 1.0 (without features like compression or pipelining) when behind a proxy – a common configuration in corporate environments – was the mainstream browser most prone to failing back to uncompressed HTTP.
Another problem found while deploying HTTP compression on large scale is due to the deflate encoding definition: while HTTP 1.1 defines the deflate encoding as data compressed with deflate (RFC 1951) inside a zlib formatted stream (RFC 1950), Microsoft server and client products historically implemented it as a "raw" deflated stream, making its deployment unreliable. For this reason, some software, including the Apache HTTP Server, only implement gzip encoding.
Compression allows a form of
In 2012, a general attack against the use of data compression, called CRIME, was announced. While the CRIME attack could work effectively against a large number of protocols, including but not limited to TLS, and application-layer protocols such as SPDY or HTTP, only exploits against TLS and SPDY were demonstrated and largely mitigated in browsers and servers. The CRIME exploit against HTTP compression has not been mitigated at all, even though the authors of CRIME have warned that this vulnerability might be even more widespread than SPDY and TLS compression combined.
In 2013, a new instance of the CRIME attack against HTTP compression, dubbed BREACH, was published. A BREACH attack can extract login tokens, email addresses or other sensitive information from TLS encrypted web traffic in as little as 30 seconds (depending on the number of bytes to be extracted), provided the attacker tricks the victim into visiting a malicious web link.
- "Using HTTP Compression (IIS 6.0)". Microsoft Corporation. Retrieved 9 February 2010.
- RFC 2616, Section 3.5: "The Internet Assigned Numbers Authority (IANA) acts as a registry for content-coding value tokens."
- "Hypertext Transfer Protocol Parameters - HTTP Content Coding Registry". IANA. Retrieved 18 April 2014.
- "Compression Tests: Results". Verve Studios, Co. Archived from the original on 21 March 2012. Retrieved 19 July 2012.
- "JSR 200: Network Transfer Format for Java Archives". The Java Community Process Program.
- "ModCompress - Lighttpd". lighty labs. Retrieved 18 April 2014.
- elinks LZMA decompression
- "[MS-PCCRTP]: Peer Content Caching and Retrieval: Hypertext Transfer Protocol (HTTP) Extensions". Microsoft. Retrieved 19 April 2014.
- "rproxy: Protocol Definition for HTTP rsync Encoding". rproxy.samba.org.
- "[MS-XCA]: Xpress Compression Algorithm". Retrieved 29 August 2015.
- "LZMA2 Compression - MozillaWiki". Retrieved 18 April 2014.
- "mget GitHub project page". GitHub. Retrieved 6 January 2017.
- "mod_deflate - Apache HTTP Server Version 2.4 - Supported Encodings".
- "Extra part of Hiawatha webserver's manual".
- "Serving static files part of Armeria's documentation".
- "How does the gzip compression check work?". httptools.dev, retrieved 10 April 2022.
- "Use compression to make the web faster". Google Inc. Retrieved 22 May 2013.
- "deflate - Why are major web sites using gzip?". Stack Overflow. Retrieved 18 April 2014.
- "Compression Tests: About". Verve Studios. Archived from the original on 2 January 2015. Retrieved 18 April 2014.
- "Lose the wait: HTTP Compression". Zoompf Web Performance. Retrieved 18 April 2014.
- Goodin, Dan (1 August 2013). "Gone in 30 seconds: New attack plucks secrets from HTTPS-protected pages". Ars Technica. Condé Nast. Retrieved 2 August 2013.
- Leyden, John (2 August 2013). "Step into the BREACH: New attack developed to read encrypted web data". The Register. Retrieved 2 August 2013.
- Sullivan, Nick (11 August 2016). "CRIME, TIME, BREACH and HEIST: A brief history of compression oracle attacks on HTTPS". Retrieved 16 August 2016.
- Goodin, Dan (3 August 2016). "HEIST exploit — New attack steals SSNs, e-mail addresses, and more from HTTPS pages". Retrieved 16 August 2016.
- Be'ery, Tal. "A Perfect Crime? TIME will tell" (PDF).
- Vanhoef, Mathy. "HEIST: HTTP Encrypted Information can be Stolen through TCP-windows" (PDF).
- RFC 2616: Hypertext Transfer Protocol – HTTP/1.1
- RFC 9110: HTTP Semantics
- HTTP Content-Coding Values by Internet Assigned Numbers Authority
- Compression with lighttpd
- Coding Horror: HTTP Compression on IIS 6.0 Archived 2014-02-06 at the Wayback Machine
- 15 Seconds: Web Site Compression at the Wayback Machine (archived July 16, 2011)
- Using HTTP Compression Archived 2016-03-14 at the Wayback Machine by Martin Brown of Server Watch
- Using HTTP Compression in PHP
- Dynamic and static HTTP compression with Apache httpd