RequestHeaders里面的Accept属性

RequestHeaders⾥⾯的Accept属性
例⼦:
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 (), 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
acceptlanguage
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.

本文发布于:2024-09-21 22:39:43,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/371610.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:类型   接受   参数   浏览器
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议