Accept-Encoding request HTTP header advertises which content encoding, usually a compression algorithm, the client is able to understand. Using content negotiation , the server selects one of the proposals, uses it and informs the client of its choice with the Content-Encoding response header.

Even if both the client and the server supports the same compression algorithms, the server may choose not to compress the body of a response, if the identity value is also acceptable. Two common cases lead to this:

  • The data to be sent is already compressed and a second compression won't lead to smaller data to be transmitted. This may be the case with some image formats;
  • The server is overloaded and cannot afford the computational overhead induced by the compression requirement. Typically, Microsoft recommends not to compress if a server uses more than 80% of its computational power.

As long as the identity value, meaning no encoding, is not explicitly forbidden, by an identity;q=0 *;q=0 without another explicitly set value for identity, the server must never send back a 406 Not Acceptable error.

注意事项:
  • An IANA registry maintains a complete list of official content encodings .

  • Two others content encoding, bzip and bzip2 , are sometimes used, though not standard. They implement the algorithm used by these two UNIX programs. Note that the first one was discontinued due to patent licensing problems.
Header type Request header
Forbidden header name yes

句法

Accept-Encoding: gzip
Accept-Encoding: compress
Accept-Encoding: deflate
Accept-Encoding: br
Accept-Encoding: identity
Accept-Encoding: *
// Multiple algorithms, weighted with the quality value syntax:
Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5
					

指令

gzip
A compression format using the Lempel-Ziv coding (LZ77), with a 32-bit CRC.
compress
A compression format using the Lempel-Ziv-Welch (LZW) algorithm.
deflate
A compression format using the zlib structure, with the deflate compression algorithm.
br
A compression format using the Brotli algorithm.
identity

Indicates the identity function (i.e. no compression, nor modification). This value is always considered as acceptable, even if not present.

*

Matches any content encoding not already listed in the header. This is the default value if the header is not present. It doesn't mean that any algorithm is supported; merely that no preference is expressed.

;q= (qvalues weighting)
Any value is placed in an order of preference expressed using a relative quality value called weight .

范例

Accept-Encoding: gzip
Accept-Encoding: gzip, compress, br
Accept-Encoding: br;q=1.0, gzip;q=0.8, *;q=0.1
					

规范

规范 Title
RFC 7231, section 5.3.4: Accept-Encoding Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Accept-Encoding Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改:
  1. HTTP
  2. Guides:
  3. Resources and URIs
    1. Identifying resources on the Web
    2. Data URIs
    3. Introduction to MIME Types
    4. Complete list of MIME Types
    5. Choosing between www and non-www URLs
  4. HTTP guide
    1. Basics of HTTP
    2. HTTP 概述
    3. Evolution of HTTP
    4. HTTP Messages
    5. A typical HTTP session
    6. Connection management in HTTP/1.x
    7. Protocol upgrade mechanism
  5. HTTP 安全性
    1. Content Security Policy (CSP)
    2. HTTP Public Key Pinning (HPKP)
    3. HTTP Strict Transport Security (HSTS)
    4. Cookie security
    5. X-Content-Type-Options
    6. X-Frame-Options
    7. X-XSS-Protection
    8. Mozilla web security guidelines
    9. Mozilla Observatory
  6. HTTP access control (CORS)
  7. HTTP authentication
  8. HTTP caching
  9. HTTP compression
  10. HTTP conditional requests
  11. HTTP content negotiation
  12. HTTP cookies
  13. HTTP range requests
  14. HTTP redirects
  15. HTTP specifications
  16. Feature policy
  17. 参考:
  18. HTTP 头
    1. Accept
    2. Accept-CH
    3. Accept-CH-Lifetime
    4. Accept-Charset
    5. Accept-Encoding
    6. Accept-Language
    7. Accept-Patch
    8. Accept-Post
    9. Accept-Ranges
    10. Access-Control-Allow-Credentials
    11. Access-Control-Allow-Headers
    12. Access-Control-Allow-Methods
    13. Access-Control-Allow-Origin
    14. Access-Control-Expose-Headers
    15. Access-Control-Max-Age
    16. Access-Control-Request-Headers
    17. Access-Control-Request-Method
    18. Age
    19. Allow
    20. Alt-Svc
    21. Authorization
    22. Cache-Control
    23. Clear-Site-Data
    24. Connection
    25. Content-Disposition
    26. Content-Encoding
    27. Content-Language
    28. Content-Length
    29. Content-Location
    30. Content-Range
    31. Content-Security-Policy
    32. Content-Security-Policy-Report-Only
    33. Content-Type
    34. Cookie
    35. Cookie2
    36. Cross-Origin-Embedder-Policy
    37. Cross-Origin-Opener-Policy
    38. Cross-Origin-Resource-Policy
    39. DNT
    40. DPR
    41. Date
    42. Device-Memory
    43. Digest
    44. ETag
    45. Early-Data
    46. Expect
    47. Expect-CT
    48. Expires
    49. Feature-Policy
    50. Forwarded
    51. From
    52. Host
    53. If-Match
    54. If-Modified-Since
    55. If-None-Match
    56. If-Range
    57. If-Unmodified-Since
    58. 索引
    59. Keep-Alive
    60. Large-Allocation
    61. Last-Modified
    62. Link
    63. Location
    64. NEL
    65. Origin
    66. Pragma
    67. Proxy-Authenticate
    68. Proxy-Authorization
    69. Public-Key-Pins
    70. Public-Key-Pins-Report-Only
    71. Range
    72. Referer
    73. Referrer-Policy
    74. Retry-After
    75. Save-Data
    76. Sec-Fetch-Dest
    77. Sec-Fetch-Mode
    78. Sec-Fetch-Site
    79. Sec-Fetch-User
    80. Sec-WebSocket-Accept
    81. Server
    82. Server-Timing
    83. Set-Cookie
    84. Set-Cookie2
    85. SourceMap
    86. Strict-Transport-Security
    87. TE
    88. Timing-Allow-Origin
    89. Tk
    90. Trailer
    91. Transfer-Encoding
    92. Upgrade-Insecure-Requests
    93. User-Agent
    94. Vary
    95. Via
    96. WWW-Authenticate
    97. Want-Digest
    98. 警告
    99. X-Content-Type-Options
    100. X-DNS-Prefetch-Control
    101. X-Forwarded-For
    102. X-Forwarded-Host
    103. X-Forwarded-Proto
    104. X-Frame-Options
    105. X-XSS-Protection
  19. HTTP 请求方法
    1. CONNECT
    2. DELETE
    3. GET
    4. HEAD
    5. OPTIONS
    6. PATCH
    7. POST
    8. PUT
    9. TRACE
  20. HTTP 响应状态码
    1. 100 Continue
    2. 101 Switching Protocols
    3. 103 Early Hints
    4. 200 OK
    5. 201 Created
    6. 202 Accepted
    7. 203 Non-Authoritative Information
    8. 204 No Content
    9. 205 Reset Content
    10. 206 Partial Content
    11. 300 Multiple Choices
    12. 301 Moved Permanently
    13. 302 Found
    14. 303 See Other
    15. 304 Not Modified
    16. 307 Temporary Redirect
    17. 308 Permanent Redirect
    18. 400 Bad Request
    19. 401 Unauthorized
    20. 402 Payment Required
    21. 403 Forbidden
    22. 404 Not Found
    23. 405 Method Not Allowed
    24. 406 Not Acceptable
    25. 407 Proxy Authentication Required
    26. 408 Request Timeout
    27. 409 Conflict
    28. 410 Gone
    29. 411 Length Required
    30. 412 Precondition Failed
    31. 413 Payload Too Large
    32. 414 URI Too Long
    33. 415 Unsupported Media Type
    34. 416 Range Not Satisfiable
    35. 417 Expectation Failed
    36. 418 I'm a teapot
    37. 422 Unprocessable Entity
    38. 425 Too Early
    39. 426 Upgrade Required
    40. 428 Precondition Required
    41. 429 Too Many Requests
    42. 431 Request Header Fields Too Large
    43. 451 Unavailable For Legal Reasons
    44. 500 Internal Server Error
    45. 501 Not Implemented
    46. 502 Bad Gateway
    47. 503 Service Unavailable
    48. 504 Gateway Timeout
    49. 505 HTTP Version Not Supported
    50. 506 Variant Also Negotiates
    51. 507 Insufficient Storage
    52. 508 Loop Detected
    53. 510 Not Extended
    54. 511 Network Authentication Required
  21. CSP directives
    1. CSP: base-uri
    2. CSP: block-all-mixed-content
    3. CSP: child-src
    4. CSP: connect-src
    5. CSP: default-src
    6. CSP: font-src
    7. CSP: form-action
    8. CSP: frame-ancestors
    9. CSP: frame-src
    10. CSP: img-src
    11. CSP: manifest-src
    12. CSP: media-src
    13. CSP: navigate-to
    14. CSP: object-src
    15. CSP: plugin-types
    16. CSP: prefetch-src
    17. CSP: referrer
    18. CSP: report-to
    19. CSP: report-uri
    20. CSP: require-sri-for
    21. CSP: require-trusted-types-for
    22. CSP: sandbox
    23. CSP: script-src
    24. CSP: script-src-attr
    25. CSP: script-src-elem
    26. CSP: style-src
    27. CSP: style-src-attr
    28. CSP: style-src-elem
    29. CSP: trusted-types
    30. CSP: upgrade-insecure-requests
    31. CSP: worker-src
  22. CORS errors
    1. Reason: CORS disabled
    2. Reason: CORS header 'Access-Control-Allow-Origin' does not match 'xyz'
    3. Reason: CORS header 'Access-Control-Allow-Origin' missing
    4. Reason: CORS header ‘Origin’ cannot be added
    5. Reason: CORS preflight channel did not succeed
    6. Reason: CORS request did not succeed
    7. Reason: CORS request external redirect not allowed
    8. Reason: CORS request not HTTP
    9. Reason: Credential is not supported if the CORS header ‘Access-Control-Allow-Origin’ is ‘*’
    10. Reason: Did not find method in CORS header ‘Access-Control-Allow-Methods’
    11. Reason: Multiple CORS header 'Access-Control-Allow-Origin' not allowed
    12. Reason: expected ‘true’ in CORS header ‘Access-Control-Allow-Credentials’
    13. Reason: invalid token ‘xyz’ in CORS header ‘Access-Control-Allow-Headers’
    14. Reason: invalid token ‘xyz’ in CORS header ‘Access-Control-Allow-Methods’
    15. Reason: missing token ‘xyz’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel
  23. Feature-Policy directives
    1. Feature-Policy: accelerometer
    2. Feature-Policy: ambient-light-sensor
    3. Feature-Policy: autoplay
    4. Feature-Policy: battery
    5. Feature-Policy: camera
    6. Feature-Policy: display-capture
    7. Feature-Policy: document-domain
    8. Feature-Policy: encrypted-media
    9. Feature-Policy: fullscreen
    10. Feature-Policy: geolocation
    11. Feature-Policy: gyroscope
    12. Feature-Policy: layout-animations
    13. Feature-Policy: legacy-image-formats
    14. Feature-Policy: magnetometer
    15. Feature-Policy: microphone
    16. Feature-Policy: midi
    17. Feature-Policy: oversized-images
    18. Feature-Policy: payment
    19. Feature-Policy: picture-in-picture
    20. Feature-Policy: publickey-credentials-get
    21. Feature-Policy: screen-wake-lock
    22. Feature-Policy: sync-xhr
    23. Feature-Policy: unoptimized-images
    24. Feature-Policy: unsized-media
    25. Feature-Policy: usb
    26. Feature-Policy: vibrate
    27. Feature-Policy: vr
    28. Feature-Policy: wake-lock
    29. Feature-Policy: xr
    30. Feature-Policy: xr-spatial-tracking
    31. web-share