目录搜索
GuidesAccess control CORSAuthenticationBrowser detection using the user agentCachingCaching FAQCompressionConditional requestsConnection management in HTTP 1.xContent negotiationContent negotiation: List of default Accept valuesCookiesCSPMessagesOverviewProtocol upgrade mechanismProxy servers and tunnelingProxy servers and tunneling: Proxy Auto-Configuration (PAC) filePublic Key PinningRange requestsRedirectionsResources and specificationsResources and URIsResponse codesServer-Side Access ControlSessionGuides: BasicsBasics of HTTPChoosing between www and non-www URLsData URIsEvolution of HTTPIdentifying resources on the WebMIME TypesMIME types: Complete list of MIME typesCSPContent-Security-PolicyContent-Security-Policy-Report-OnlyCSP: base-uriCSP: block-all-mixed-contentCSP: child-srcCSP: connect-srcCSP: default-srcCSP: font-srcCSP: form-actionCSP: frame-ancestorsCSP: frame-srcCSP: img-srcCSP: manifest-srcCSP: media-srcCSP: object-srcCSP: plugin-typesCSP: referrerCSP: report-uriCSP: require-sri-forCSP: sandboxCSP: script-srcCSP: style-srcCSP: upgrade-insecure-requestsCSP: worker-srcHeadersAcceptAccept-CharsetAccept-EncodingAccept-LanguageAccept-RangesAccess-Control-Allow-CredentialsAccess-Control-Allow-HeadersAccess-Control-Allow-MethodsAccess-Control-Allow-OriginAccess-Control-Expose-HeadersAccess-Control-Max-AgeAccess-Control-Request-HeadersAccess-Control-Request-MethodAgeAllowAuthorizationCache-ControlConnectionContent-DispositionContent-EncodingContent-LanguageContent-LengthContent-LocationContent-RangeContent-TypeCookieCookie2DateDNTETagExpectExpiresForwardedFromHeadersHostIf-MatchIf-Modified-SinceIf-None-MatchIf-RangeIf-Unmodified-SinceKeep-AliveLarge-AllocationLast-ModifiedLocationOriginPragmaProxy-AuthenticateProxy-AuthorizationPublic-Key-PinsPublic-Key-Pins-Report-OnlyRangeRefererReferrer-PolicyRetry-AfterServerSet-CookieSet-Cookie2SourceMapStrict-Transport-SecurityTETkTrailerTransfer-EncodingUpgrade-Insecure-RequestsUser-AgentUser-Agent: FirefoxVaryViaWarningWWW-AuthenticateX-Content-Type-OptionsX-DNS-Prefetch-ControlX-Forwarded-ForX-Forwarded-HostX-Forwarded-ProtoX-Frame-OptionsX-XSS-ProtectionMethodsCONNECTDELETEGETHEADMethodsOPTIONSPATCHPOSTPUTStatus100 Continue101 Switching Protocols200 OK201 Created202 Accepted203 Non-Authoritative Information204 No Content205 Reset Content206 Partial Content300 Multiple Choices301 Moved Permanently302 Found303 See Other304 Not Modified307 Temporary Redirect308 Permanent Redirect400 Bad Request401 Unauthorized403 Forbidden404 Not Found405 Method Not Allowed406 Not Acceptable407 Proxy Authentication Required408 Request Timeout409 Conflict410 Gone411 Length Required412 Precondition Failed413 Payload Too Large414 URI Too Long415 Unsupported Media Type416 Range Not Satisfiable417 Expectation Failed426 Upgrade Required428 Precondition Required429 Too Many Requests431 Request Header Fields Too Large451 Unavailable For Legal Reasons500 Internal Server Error501 Not Implemented502 Bad Gateway503 Service Unavailable504 Gateway Timeout505 HTTP Version Not Supported511 Network Authentication RequiredStatus
文字

Content-Encoding实体头用于压缩媒体类型。如果存在,它的值表示哪些编码应用于实体主体。它让客户知道,如何解码以获取Content-Type标题引用的媒体类型。

建议尽可能压缩数据并因此使用此字段,但某些类型的资源(如 jpeg 图像)已被压缩。有时使用额外的压缩不会减少有效载荷的大小,甚至可能使有效载荷更长。

Header type

Entity header

Forbidden header name

no

语法

Content-Encoding: gzip
Content-Encoding: compress
Content-Encoding: deflate
Content-Encoding: identity
Content-Encoding: br// Multiple, in the order in which they were appliedContent-Encoding: gzip, identity
Content-Encoding: deflate, gzip

指令

gzip一种使用 Lempel-Ziv 编码( LZ77 )和32位 CRC 的格式。这最初是 UNIX gzip 程序的格式。

x-gzip为了兼容性的目的,HTTP / 1.1 标准还建议支持该内容编码的服务器应该将其识别为别名。

compress使用 Lempel-Ziv-Welch( LZW )算法的格式。值名取自实施此算法的 UNIX 压缩程序。

与大多数 UNIX 发行版已经消失的压缩程序一样,目前几乎没有浏览器使用这种内容编码,部分原因是由于专利问题(已在2003年过期)。

deflate使用 deflate 压缩算法(在 RFC 1951中定义)使用 zlib 结构(在 RFC 1950中定义)。

identity指示身份功能(即不压缩,也不修改)。除非明确指定,否则此标记始终被视为可接受。

br使用 Brotli 算法的格式。

例子

用 gzip 压缩

在客户端,您可以公布一个将在 HTTP 请求中发送的压缩方案列表。Accept-Encoding header 被用于协商内容编码。

Accept-Encoding: gzip, deflate

服务器响应所使用的方案,由Content-Encoding响应 header 。

Content-Encoding: gzip

请注意,服务器没有义务使用任何压缩方法。压缩高度依赖于服务器设置和使用的服务器模块。

规范

Specification

Title

RFC 7231, section 3.1.2.2: Content-Encoding

Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content

RFC 7932: Brotli Compressed Data Format

Brotli Compressed Data Format

浏览器兼容性

Feature

Chrome

Edge

Firefox

Internet Explorer

Opera

Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

br

50

No

44.0

No

36.0

No

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

br

51

51

No

44.0

No

No

No

上一篇:下一篇: