api - 在什么情况下代理会删除 HTTP 请求 header ?

标签 api http rest language-agnostic rfc2616

我正在研究各种 RESTfully 版本控制 API 的方法,并且存在三个主要竞争者。我相信我已经决定使用 X-API-Version。撇开争论不谈,反对使用该 header 和一般自定义 header 的一个论据是,您无法控制 header 何时被代理服务器操纵。我很好奇现实世界中有哪些这样的例子,它什么时候发生在整个 Internet 上,什么时候它可能用于 Intranet 或服务器集群,或者什么时候它可能发生在任何其他情况下。

最佳答案

Guidelines for Web Content Transformation Proxies 1.0几乎是了解和预测符合标准的代理服务器行为的权威指南。就您的问题而言,Proxy Forwarding of Request文档的一部分可能特别有用。

每个代理软件包及其各自的配置会有所不同,但 HTTP 代理通常应遵循 W3C 指南。以下是一些亮点。

4.1 代理转发请求:

Other than to convert between HEAD and GET proxies must not alter request methods.

If the request contains a Cache-Control: no-transform directive, proxies must not alter the request other than to comply with transparent HTTP behavior defined in [RFC 2616 HTTP] sections section 14.9.5 and section 13.5.2 and to add header fields as described in 4.1.6 Additional HTTP Header Fields below.

4.1.3 处理非 W​​eb 浏览器的请求者

Before altering aspects of HTTP requests and responses proxies need to take account of the fact that HTTP is used as a transport mechanism for many applications other than "Traditional Browsing". Increasingly browser based applications involve exchanges of data using XMLHttpRequest (see 4.2.8 Proxy Decision to Transform) and alteration of such exchanges is likely to cause misoperation.

4.1.5 更改 HTTP header 字段值

Other than the modifications required by [RFC 2616 HTTP] proxies should not modify the values of header fields other than the User-Agent, Accept, Accept-Charset, Accept-Encoding, and Accept-Language header fields and must not delete header fields (see 4.1.5.5 Original Header Fields).

Other than to comply with transparent HTTP operation, proxies should not modify any request header fields unless one of the following applies:

  • 由于服务器响应请求“ Not Acceptable ”,用户将被禁止访问内容(参见 4.2.4 服务器拒绝 HTTP 请求);

  • 用户明确要求重构桌面体验(参见 4.1.5.3 用户选择重构体验);

  • 请求是请求序列的一部分,请求序列包含同一网站上包含的资源或链接的资源(请参阅 4.1.5.4 请求序列)。

这些情况在以下各节中有详细说明。

注意:

It is emphasized that requests must not be altered in the presence of Cache-Control: no-transform as described under 4.1.2 no-transform directive in Request.

The URI referred to in the request plays no part in determining whether or not to alter HTTP request header field values. In particular the patterns mentioned in 4.2.8 Proxy Decision to Transform are not material.

4.1.6 额外的 HTTP header 字段

无论是否存在 no-transform 指令:

  • 代理应将请求发起者的 IP 地址添加到 X-Forwarded-For HTTP header 字段中逗号分隔列表的末尾;

  • 代理必须(根据 RFC 2616)包含一个 Via HTTP header 字段(请参阅 4.1.6.1 Via header 字段的代理处理)。


还有很多关于更改响应 header 以及能够检测到这些更改的信息。

至于网络服务 REST API 版本控制,在 Best practices for API versioning? 有一个非常清晰和有用的 SO 线程这应该会提供大量有用的见解。

我希望所有这些对您有所帮助。保重。

关于api - 在什么情况下代理会删除 HTTP 请求 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20820572/

相关文章:

json - 为什么我的 Spotify 应用程序中对外部 API 的 JSON 请求被取消?

ruby-on-rails - Ruby 数组插入神秘字符

python - 如何使用 python 使用驱动器 API 将文件上传到谷歌驱动器?

http - 从https网站到localhost上的http服务器通信,跨域

java - RFC 2388 多部分 POST 的服务器实现与 RFC 2047 冲突?

PHP $_POST 空 - 变量存储在 $_REQUEST 中

java - SOAP 到 REST 转换 : Fresh or reuse?

api - SharePoint REST API getFolderByServerRelativeUrl 不返回任何内容

macos - Paw 如何从 csv 或 json 文件中读取动态值?

java - Jersey Rest 服务的 ResourceConfig 和 ServletContextListener 之间的区别