自定义HTTP标头:命名约定 [英] Custom HTTP headers : naming conventions

查看:105
本文介绍了自定义HTTP标头:命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的一些用户要求我们在我们发送的请求的 HTTP标头中包含与其帐户相关的数据,甚至是我们从API获得的响应。
添加自定义HTTP标头的一般惯例是命名格式 ......等等。

Several of our users have asked us to include data relative to their account in the HTTP headers of requests we send them, or even responses they get from our API. What is the general convention to add custom HTTP headers, in terms of naming, format... etc.

另外,随意发布您在网上偶然发现的这些智能用法;我们正在尝试使用最好的目标来实现这一目标:)

Also, feel free to post any smart usage of these that you stumbled upon on the web; We're trying to implement this using what's best out there as a target :)

推荐答案

2012年6月,推荐弃用使用X-前缀已成为 RFC 6648 的正式版。以下是相关的引用:

On June 2012, the deprecation of recommendation to use the "X-" prefix has become official as RFC 6648. Below are cites of relevance:


3。新参数创作者的建议



...

3. Recommendations for Creators of New Parameters

...


  1. 不应该在参数名称前加上X-或类似的
    结构。







4。协议设计师的建议



...

4. Recommendations for Protocol Designers

...


  1. 不应该禁止带有X-前缀或类似
    构造的参数被注册。

  1. SHOULD NOT prohibit parameters with an "X-" prefix or similar constructs from being registered.

不得规定带参数的参数X-前缀或
类似的结构需要被理解为非标准化。

MUST NOT stipulate that a parameter with an "X-" prefix or similar constructs needs to be understood as unstandardized.

不得规定没有X-前缀的参数或
类似的结构需要被理解为标准化。

MUST NOT stipulate that a parameter without an "X-" prefix or similar constructs needs to be understood as standardized.


注意不应该(气馁)与绝不(禁止)不同,另见 RFC 2119 关于这些关键字的另一个规范。换句话说,你可以继续使用X-前缀标题,但不推荐使用它,你可能不会将它们记录为公共标准。

Note that "SHOULD NOT" ("discouraged") is not the same as "MUST NOT" ("forbidden"), see also RFC 2119 for another spec on those keywords. In other words, you can keep using "X-" prefixed headers, but it's not recommended and you may not document them as if they are public standard.

2011年6月,第一个 IETF草案已发布弃用对非标准标头使用X-前缀的建议。原因是当前缀为X-的非标准头文件成为标准时,删除X-前缀会破坏向后兼容性,迫使应用程序协议支持这两个名称(例如, x-gzip & gzip 现在相当于)。所以,建议只是在没有X-前缀的情况下将它们命名为明智地

On June 2011, the first IETF draft was posted to deprecate the recommendation of using the "X-" prefix for non-standard headers. The reason is that when non-standard headers prefixed with "X-" become standard, removing the "X-" prefix breaks backwards compatibility, forcing application protocols to support both names (E.g, x-gzip & gzip are now equivalent). So, the recommendation is to just name them sensibly without the "X-" prefix.

建议 以X-开头。例如。 X-Forwarded-For X-Requested-With 。这也在a.o中提到。 RFC 2047 的第5部分。

The recommendation is was to start their name with "X-". E.g. X-Forwarded-For, X-Requested-With. This is also mentioned in a.o. section 5 of RFC 2047.

这篇关于自定义HTTP标头:命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆