内容协商、(请求头、响应头)字段总结

一、Content negotiation

Content negotiation refers to mechanisms defined as a part of HTTP that make it possible to serve different versions of a document (or more generally, representations of a resource) at the same URI, so that user agents can specify which version fits their capabilities the best. One classical use of this mechanism is to serve an image in GIF or PNG format, so that a browser that cannot display PNG images (e.g. MS Internet Explorer 4) will be served the GIF version.
内容协商是HTTP的机制,该机制使得同一URI上可以提供文档的不同版本(或更笼统地说,资源的表示形式),以便user agents可以指定最适合的版本。这种机制的一种经典用法是提供GIF或PNG格式的图像,以便将无法显示PNG图像的浏览器(例如MS Internet Explorer 4)提供给GIF版本。

A resource may be available in several different representations; for example, it might be available in different languages or different media types. One way of selecting the most appropriate choice is to give the user an index page and let them select the most appropriate choice; however it is often possible to automate the choice based on some selection criteria.
资源可能有几种不同的表示形式。例如,它可能以不同的语言或不同的媒体类型提供。选择最合适的选择的一种方法是给用户一个索引页,并让他们选择最合适的选择。但是,通常有可能根据某些选择标准来自动进行选择。

1.Server-driven

概括:浏览器把偏爱通过header告诉服务器,服务器在内容变体列表中选择合适的形式返回
还有Vary用于协商缓存。

Server-driven or proactive content negotiation is performed by algorithms on the server which choose among the possible variant representations. This is commonly performed based on user agent-provided acceptance criteria.
服务器驱动或主动内容协商由服务器上的算法执行,这些算法在可能的变体表示形式中进行选择。通常根据用户代理提供的接受标准执行此操作。

To summarize how this works, when a user agent submits a request to a server, the user agent informs the server what media types or other aspects of content presentation it understands with ratings of how well it understands them. More precisely, the user agent provides HTTP headers that lists acceptable aspects of the resource and quality factors for them. The server is then able to supply the version of the resource that best fits the user agent’s needs.
概括地说,这是如何工作的,当user agent向服务器提交请求时,user agent会告知服务器它所理解的内容呈现的媒体类型或其他方面,以及对它们的理解程度。更准确地说,user agent提供HTTP headers,其中列出了可接受的资源方面和质量因数。然后,服务器便能够提供最适合user agent需求的资源版本。

For example, a browser could indicate that it would like information in German by setting the Accept-Language like this:
例如,浏览器可以通过这样设置来表明它希望用德语显示信息Accept-Language:

Accept-Language: de

Note that this preference will only be applied when there is a choice of representations and they vary by language.
请注意,只有在可以选择表示形式并且它们随语言而变化时,才会应用此header。(也就是说,若服务端只有1种语言、格式等,则客户端再指定没有意义)

As an example of a more complex request, this browser has been configured to accept French and English, but prefer French, and to accept various media types, preferring HTML over plain text or other text types, and preferring GIF or JPEG over other media types, but also allowing any other media type as a last resort:
作为更复杂的请求的示例,此浏览器已配置为接受法语和英语,但更喜欢法语;接受各种媒体类型,比如文本类型,更偏爱HTML,image类型更偏爱GIF或JPEG ,但也允许任何其他媒体类型作为最后手段:

Accept-Language: fr; q=1.0, en; q=0.5
Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1

在这里插入图片描述

2.Agent-driven

与Server-driven相反,服务器将变体列表返回,agent选择。

二、请求头

请求报文
​​在这里插入图片描述
在这里插入图片描述

1.Accept
  • 客户端能够处理的媒体类型,及媒体类型优先级

  • 媒体类型:文本文件text/html、图片文件image/jpeg、视频文件video/mpeg、应用程序使用的二进制文件application/zip

Accept:text/plain;q=0.3,text/htm

权重q范围0~1。默认为1,当服务器提供多种内容时,会优先返回权重值最高的媒体类型。

2.Host
  • 告诉服务器,请求的资源所处的互联网主机名和端口号
3.Referer
  • 请求的URL是从哪个web页面发起的

  • 常用于网站的访问统计:比如我在很多地方都做了广告链接到我网站的主页,这时候我就可以通过referer来查看哪些地方跳转过来的人多,说明广告效果好;

  • 也可以用于防盗链

4.User-Agent

The User-Agent request header is a characteristic string that lets servers and network peers identify the application, operating system, vendor, and/or version of the requesting user agent.

以Firefox为例:

Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion

Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0
  • Mozilla/5.0 是一个通用标记符号,用来表示与 Mozilla 兼容,这几乎是现代浏览器的标配。

  • platform:浏览器锁运行的原生系统平台(Windows、Mac、Linux、Android)

  • rv:geckoversion:Gecko发布的版本号。Gecko是Rendering Engine,也是浏览器的内核。(常见的浏览器内核参考https://www.cnblogs.com/baihuitestsoftware/articles/6689012.html

  • Gecko/geckotrail:表示该浏览器基于Gecko渲染引擎,在桌面浏览器中,geckotrail 是固定字符串20100101

  • Firefox/firefoxversion:表示该浏览器是Firefox,版本信息为75.0

其他浏览器User-Agent参考:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent

5.条件请求

具体见:https://blog.csdn.net/jiangshangchunjiezi/article/details/88581824

三、响应头

响应报文
在这里插入图片描述
在这里插入图片描述
具体见:https://blog.csdn.net/jiangshangchunjiezi/article/details/88591341

四、实体首部字段

具体见:https://blog.csdn.net/jiangshangchunjiezi/article/details/88591818

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值