Request Headers 里面的 Accept 属性

来源:互联网 发布:c语言中制表符怎么用? 编辑:程序博客网 时间:2024/06/10 05:23

文章来源:https://tools.ietf.org/html/rfc7231#section-1.1

例子:

  Accept:text/html,application/xhtm +xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding:gzip, deflate, sdch, br
  Accept-Language:zh-CN,zh;q=0.8
  Connection:keep-alive

q=0.9: q:表示优先权,先接受那个类型。

这个Accept 头属性能被用在浏览器响应能接受的media 类型。

   The "Accept" header field can be used by user agents to specify  response media types that are acceptable. 

    这个“Accept” 头属性能被浏览器用来指定响应的media 类型,表示自己可以接受的类型。

  Accept header fields can  be used to indicate that the request is specifically limited to a  small set of desired types, 

 as in the case of a request for an in-line image.

     Accept = #( media-range [ accept-params ])

     media-range    = ( "*/*":所有类型

                      / ( type "/""*" ) :type 类型子类型

                      / ( type "/"subtype ) type/type的子类型

                      ) *( OWS ";"OWS parameter )

     accept-params  = weight *( accept-ext )

     accept-ext = OWS ";" OWS token ["=" ( token / quoted-string ) ]

 

   The asterisk "*" character is used to group media types into ranges,

   with "*/*" indicating all media types and "type/*" indicating all  subtypes of that type. 

  The media-range can include media type   parameters that are applicable to thatrange.

   Each media-range might be followed by zeroor more applicable media  type parameters (e.g., charset), an optional"q" parameter   for   indicating a relative weight (Section 5.3.1), and then zero or more

   extension parameters.  

   The "q" parameter is necessary if any  extensions (accept-ext) are present, since it acts as a separator

   between the two parameter sets.

    q 参数是必要的,如果一些扩展是出现了,因为他在两个参数集里面起作用。

      Note: Use of the "q" parameter name to separate media type   parameters from Accept extension parameters is due to historical   practice. 

     注:使用q参数把media 类型参数和可接受的扩展参数相分离是由于历史的实践。

     Although this prevents any media type parameter named   "q" from being used with a media range, 

    尽管阻止命名q的一些media 类型参数?不一个media 范围里使用命名q的一些media 类型参数:不知道是哪些media 类型命名了?

    such an event is believed  to be unlikely given the lack of any"q" parameters in the IANA media type registry and the rare usage     of any media type  parameters in Accept. 

    Future media types are discouraged from  registering any parameter named"q".

   The example

     Accept: audio/*; q=0.2, audio/basic 

     is interpreted as "I prefer audio/basic, but send me any audio type:

     我更喜欢音频/basic,但却给我任何音频类型.

   if it is the best available after an 80% mark down in quality.在质量上下降80%后,如果它是最好的可利用的???

   A request without any Accept header field implies that the user agent   will accept any media type in response. 

   一个请求没有任何的Accept 头属性暗示浏览器可以接受任何类型回应。

 If the header field is  present in a request and none of the available representations for   the response have a media type that is listed as acceptable, 

  如果头属性出现在一个request中,但是tomcat 没有这样类型回应,将送一个406的回应或是忽略头属性,好像它不受内容的约束。

     the   origin server can either honor the header field by sending a 406 (Not   Acceptable) response or disregard the header field by treating the   response as if it is not subject to content negotiation.

 

   A more elaborate example is

     Accept: text/plain; q=0.5, text/html,

             text/x-dvi; q=0.8, text/x-c

   Verbally, this would be interpreted as"text/html and text/x-c are  the equally preferred media types, but if they do not exist, then

   口头上,这个将被解释作为 text/html and text/x-c 是相等更好的media 类型,但是如果他们不存在,送一个 text/x-dvi 表示,如果这个不存在,送一个text/plain 表示

   send the text/x-dvi representation, and if that does not exist, send  the text/plain representation".

   Media ranges can be overridden by more specific media ranges or  specific media types.  

    Media 范围能被更具体的media 范围 或具体的media 类型重写。

  If more than one media range applies to a   given type, the most specific reference has precedence.  

如果 多个media 范围应用到一个给定的类型,  最具体的引用具有优先权。

For example,

     Accept: text/*, text/plain,text/plain;format=flowed, */*

   有下面的优先级

   1. text/plain;format=flowed

   2. text/plain

   3. text/*

   4. */*

   The media type quality factor associated with a given type is  determined by finding the media range with the highest precedence

   that matches the type.  

    media type的quality值和一个给定类型相关联,这个类型是首先查找一个media 的范围,取最高优先权的类型。

   For example,

     Accept: text/*;q=0.3, text/html;q=0.7,text/html;level=1,text/html;level=2;q=0.4, */*;q=0.5

   关联如下:

   +-------------------+---------------+

   | Media Type        | Quality Value |

   +-------------------+---------------+

   | text/html;level=1 |      1            |

   | text/html             |     0.7          |

   | text/plain            |     0.3          |

   | image/jpeg         |     0.5         |

   | text/html;level=2 |    0.4         |

   | text/html;level=3 |    0.7         |

   +-------------------+---------------+

   Note: A user agent might be provided with a default set of quality  values for certain media ranges. 

      However, unless the user agent is a   closed system that cannot interact with other rendering agents, this

   default set ought to be configurable by the user.

阅读全文
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 q自己的活干完了该怎么办 在应用宝下载的游戏搜不到了怎么办 衣服有图片在淘宝找不到同款怎么办 淘宝卖家小儿说质量不合格怎么办 订单显示显示已签收没收到货怎么办 网上买过的东西查不到订单号怎么办 亚航的组合机票飞机延误怎么办 在微信上面对面红包被骗了钱怎么办 人欠我钱不给我怎么办 微信号被骗走然后骗了朋友钱怎么办 微信手机充值不到帐怎么办 中银香港密码器坏了怎么办 香港恒生银行的编码器丢了怎么办 淘宝拍下订单发货物流不显示怎么办 wish查到仿品审核变慢怎么办 淘宝卖家订单号错误无法修改怎么办 顺丰快递运单号微信扫描取消怎么办 买的王者荣耀号有守护平台怎么办 融e联登录密码错三次怎么办 金融e家u盾密码忘了怎么办 用工行网银转账后想取消交易怎么办 工行融e借没有密码器怎么办 工行融e借密码器丢了怎么办 工行融e联手机登录密码忘记怎么办 领导给员工抱怨工作太烦怎么办 员工抱怨忙的忙死闲的闲死怎么办 爱上骗我进传销的人该怎么办 尚赫辟谷期间吃了东西怎么办 肾结石掉在输尿管里面好痛怎么办 寄的快递快递单号找不到了怎么办 手机停机但是快递是这个号码怎么办 百世通快递卡在一个地方没动怎么办 电信无限流量20g用完了怎么办 至尊宝qq密保手机被更换怎么办 至尊宝账户密保手机被改怎么办 照片放到私密相册找不到了怎么办 出口报关报错境内货源地怎么办? 微信提现未到账交易记录删了怎么办 支付宝忘记密码就可以登陆怎么办 电脑上登陆QQ忘记密码了怎么办? 电脑被管理员限制登录微信了怎么办