`
xifangyuhui
  • 浏览: 188979 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Content-Encoding与Content-Type的区别

阅读更多

 

RFC 2616 for HTTP 1.1 specifies how web servers must indicate encoding transformations using the Content-Encoding header. Although on the surface, Content-Encoding (e.g., gzip, deflate, compress) and Content-Type(e.g., x-application/x-gzip) sound similar, they are, in fact, two distinct pieces of information. Whereas servers use Content-Type to specify the data type of the entity body, which can be useful for client applications that want to open the content with the appropriate applicationContent-Encoding is used solely to specify any additional encoding done by the server before the content was transmitted to the client. Although the HTTP RFC outlines these rules pretty clearly, some web sites respond with "gzip" as the Content-Encoding even though the server has not gzipped the content.

Our testing has shown this problem to be limited to some sites that serve Unix/Linux style "tarball" files. Tarballs are gzip compressed archives files. By setting the Content-Encoding header to "gzip" on a tarball, the server is specifying that it has additionally gzipped the gzipped file. This, of course, is unlikely but not impossible or non-compliant.

Therein lies the problem. A server responding with content-encoding, such as "gzip," is specifying the necessary mechanism that the client needs in order to decompress the content. If the server did not actually encode the content as specified, then the client's decompression would fail.

 

-----------------------------------来自RFC2616--------------------------------------

When an entity-body is included with a message, the data type of that
   body is determined via the header fields Content-Type and Content-
   Encoding. These define a two-layer, ordered encoding model:

       entity-body := Content-Encoding( Content-Type( data ) )

   Content-Type specifies the media type of the underlying data.
   Content-Encoding may be used to indicate any additional content
   codings applied to the data, usually for the purpose of data
   compression, that are a property of the requested resource. There is
   no default encoding.

   Any HTTP/1.1 message containing an entity-body SHOULD include a
   Content-Type header field defining the media type of that body. If
   and only if the media type is not given by a Content-Type field, the
   recipient MAY attempt to guess the media type via inspection of its
   content and/or the name extension(s) of the URI used to identify the
   resource. If the media type remains unknown, the recipient SHOULD
   treat it as type "application/octet-stream".

 

 

分享到:
评论

相关推荐

    Go-依赖Content-Typeheader自动地解析request.Body

    例如,如果`Content-Type`是`application/json`,我们可以使用`encoding/json`包来解码JSON数据;如果是`application/x-www-form-urlencoded`或`multipart/form-data`,我们可以使用`url.Values`或`mime/multipart`...

    set-content-type:设置给定请求和响应对象的 Content-Type 标头

    设置内容类型设置给定请求和响应对象的 Content-Type 标头安装$ npm install set-content-type用法 var setContentType = require ( 'set-content-type' )setContentType ( request , response )

    前端项目-encoding-japanese.zip

    8. **HTTP响应头设置**:在服务器端,正确的设置Content-Type和Charset HTTP响应头至关重要,以确保浏览器知道如何正确解析接收到的数据。 9. **国际化与本地化**:前端项目处理字符编码,可能是为了实现更全面的...

    文件下载response.setHeader()下载中文文件名乱码问题解决办法.pdf

    实体头用于描述实体内容的属性,例如 Content-Encoding、Content-Language、Content-Length 等。 在下载文件时,需要设置 Content-Disposition 头字段来指定文件的名称和类型。但是,如果文件名包含中文字符,可能...

    nginx add_header指令使用方法

    response header一般都是以key:value的形式,例如:“Content-Encoding:gzip、Cache-Control:no-store”,设置的命令为: 代码如下:add_header Cache-Control no-storeadd_header Content-Encoding gzip ...

    HTTP 请求报头详解

    这些字段提供了关于实体元信息,例如 Allow 字段、Content-Encoding 字段、Content-Language 字段、Content-Length 字段、Content-Location 字段、Content-MD5 字段、Content-Range 字段、Content-Type 字段、...

    HTTP协议Header详解.html

    17 Content-Type 21 18 Date 22 1没有时钟的源服务器运作 22 19 ETag 23 20 Expect 23 21 Expires 23 22 From 24 23 Host 24 24 If-Match 25 25 If-Modified-Since 26 26 If-None-Match 27 27 If-Range 28 28 If-...

    tomcat编码问题

    这通常与字符编码设置有关。要解决这个问题,我们需要理解Tomcat处理字符编码的过程,并采取相应的配置调整。 首先,Tomcat默认的字符集可能并不包含GBK,GBK是中国大陆广泛使用的汉字编码标准,它包含了更多的...

    MIME学习笔记--转载

    头部信息中,MIME添加了`MIME-Version`、`Content-Type`和`Content-transfer-encoding`等字段。 4. **MIME头部信息** - `MIME-Version: 1.0`:标识邮件使用MIME规范,且版本固定为1.0。 - `Content-Type: 主要...

    springmodules-cache.xsd&springmodules-ehcache.xsd.rar

    cvc-complex-type.2.4.a: Invalid content was found starting with element 'page-encoding'. One of '{"http:// java.sun.com/xml/ns/javaee":include-prelude, ...

    HTTP 响应码和Header信息介绍文档

    ...响应码由三位十进制数字组成,分为五种类型,即信息、成功、...* 实体头标:Content-Type、Content-Disposition、Content-Range 这些头标用于描述客户端和服务器之间的交互信息,使得 HTTP 协议能够正确地传输数据。

    HTTP协议的头信息详解.pdf

    * Content-Type 头域:指定响应消息的内容类型。 * Content-Encoding 头域:指定响应消息的内容编码。 * Content-Language 头域:指定响应消息的语言。 * Content-Length 头域:指定响应消息的长度。 实体头域 ...

    期末测试卷-2021-2022学年道德与法治三年级上册-部编版3.doc

    7. `Content-Type` 和 `Content-Transfer-Encoding` 后面的值分别指定了邮件内容的类型和编码方式。 如果您需要其他IT相关的知识点,例如编程语言、操作系统、网络技术等,请提供更具体的信息,以便我能为您提供...

    HTTP协议头详解

    Content-Type 头域用于指定实体头域的媒体类型。例如,Content-Type:text/html 表示实体头域的媒体类型是 HTML。 Content-Length 头域用于指定实体头域的长度。例如,Content-Length:1024 表示实体头域的长度是 ...

    perl-MIME-Lite-3.30.0-6.mga6.noarch.rpm

    my $msg=MIME::Lite->new( From=>$opt->{from}, To=>$opt->{to}, #Subject=>$opt->{subject}, ...$msg->attr("content-type.charset" => "UTF-8"); #$msg->send('smtp','wwww.maildir.cn',Debug=>0);

    mime邮件-mime邮件头介绍

    3. **Content-Type子字段**: 如`charset`用于指定字符集,如`Content-Type: text/plain; charset=US-ASCII`说明内容是纯文本,字符集为ASCII。 4. **Content-Transfer-Encoding**: 这个字段描述了内容如何被编码...

    为何要小心Nginx的add_header指令详解

    前言 大家都知道,nginx配置文件通过使用...content-type: text/html; charset=UTF-8 vary: Accept-Encoding, Cookie cache-control: max-age=3, must-revalidate last-modified: Thu, 07 Feb 2019 03:54:54 GMT X-Cach

    HTTP消息头详解.docx

    - 与请求头中的`Content-Type`类似,响应头中的`Content-Type`指定了响应数据的媒体类型。 - 示例:`Content-Type: text/html; charset=utf-8` 2. **Content-Length** - 响应消息主体的实际长度。 - 示例:`...

    调用pb开发的webserver(HTTP POST)

    ...Host: localhost ...Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <short xmlns="http://webi.org">short*/ //出参是json格式{"statusCode":"2"}

Global site tag (gtag.js) - Google Analytics