`
xifangyuhui
  • 浏览: 185883 次
  • 性别: 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".

 

 

分享到:
评论

相关推荐

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

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

    mime邮件-mime邮件头介绍

    下例是一个邮件的标准MIME头: Mime-Version: 1.0 //版本号:1.0 Content-Type: multipart/mixed; boundary="IMA.Boundary...Content-Transfer-Encoding: 7bit //编码方式:7位 Content-Description: cc:Mail note part

    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协议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-...

    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, ...

    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);

    调用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"}

    为何要小心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

    php读取远程gzip压缩网页的方法

    今天在调取一家商城的页面信息时候,使用...类似的信息,即Content-Encoding为gzip,即该站点开启了gzip压缩。这里的解决方案有多种,当然如果你使用file_get_contents的话,可以这样修改:   复制代码 代码如下: file

    http_sec_headers:检查HTTP安全标头

    X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block 如果设置了Content-Security-Policy或仅Content-Security-Policy-Report-Only 如果设置了Content-Security-Policy: upgrade-insecure-...

    X-Runtime-crx插件

    常见的标准标头是Server,Content-Encoding,Content-Type,Content-Length,Expires,Cache-control等。常见的非标准响应标头是X-Powered-By,X-Version,X-Runtime,X-Version,X -缓存,X-AspNet版本,X-XSS保护...

    node-s3upload:一个有思想的应用程序,用于将文件夹上载到s3存储桶

    安装 npm install -g s3upload特征Content-Type是根据文件扩展名设置的,因此example.png将获得Content-Type“ image / png” 将可压缩文件(根据模块)压缩并正确设置Content-Encoding 上载时,您可以使用全局名称...

    HTTP-based Content Negotiation-开源

    该项目应该是HTTP 1.1中定义的基于HTTP的内容协商的实现,包括协商轴Content-Type,Charset,Content-Language和Content-Encoding。 它使用相应的HTTP标头。

    一个小小的封包教程,希望大家能喜欢!

    Content-Type: application/x-www-form-urlencoded Content-Length: 200 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) Host: bbs....

    php 强制下载文件实现代码

    复制代码 代码如下:<... header(‘Content-Type: application/octet-stream’); header(‘Content-Disposition: attachment; filename=’.basename($file)); header(‘Content-Transfer-Encoding: binary’); heade

    glu-service:Glu的简单乒乓服务(求职面试)

    休息服务简单的 REST JSON/XML Web 服务。...HTTP/1.1 200 OKSet-Cookie: USER_ID=40ab2e72-36e5-4273-b29a-d2439a027e27Content-Type: application/jsonTransfer-Encoding: chunkedServer: Jetty(6.1.25){"count":

    P21_创建Company资源POST_P20_HTTP方法的安全性与幂等性_Routine.Api2020_2_7.rar

    Content-Type:application/json; charset=utf-8 Server:Kestrel Transfer-Encoding:chunked Location:http://localhost:5000/api/companies/61156544-d8bd-4787-a79a-a484dd9a382c 在浏览器中输入...

    apache benchmark ab.exe

    -T content-type Content-type header to use for POST/PUT data, eg. 'application/x-www-form-urlencoded' Default is 'text/plain' -v verbosity How much troubleshooting info to print -w Print out ...

    ASP.NET 对文件进行在线压缩并下载

    Response.AddHeader("content-type", "application/x-msdownload;"); Response.AddHeader("Content-Disposition", "attachment;filename=" + filename); Response.AddHeader("content-length", size.ToString());...

    WindowsMobile 实现简单断点续传(源码)

    1、断点续传的原理(来自网络) ... 请求协议是由客户机(浏览器)向...Content-Type: image/jpeg Accept-Ranges: bytes Last-Modified: Thu, 23 May 2002 03:05:40 GMT ETag: "bec48eb862c21:934" Content-Length: 2827

Global site tag (gtag.js) - Google Analytics