HTTP 标头换行样式 [英] HTTP header line break style

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

问题描述

哪种换行符样式更适合用于 HTTP 标头: ,为什么?

Which line break style is preferable for use in HTTP headers: or , and why?

推荐答案

,因为它在协议规范中被定义为换行符.RFC2616 在第 2.2 节基本规则"的开头声明,非常明确:

, because it's defined as the line break in the protocol specification. RFC2616 states at the beginning of section 2.2, "Basic Rules", quite unambiguously:

CR =
LF =
HTTP/1.1 将序列 CR LF 定义为除 entity-body 之外的所有协议元素的行尾标记

CR = <US-ASCII CR, carriage return (13)>
LF = <US-ASCII LF, linefeed (10)>
HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all protocol elements except the entity-body

RFC2616 在技术上已被 RFC7230 淘汰,但它没有做出太大的改变,并在 第 3 节,并且 RFC 参考了 RFC5234,附录 B.1 定义CRLF";如%x0D %x0A.

RFC2616 was technically obsoleted by RFC7230, but it makes no drastic changes and again calls out CRLF as the delimiter in section 3, and that RFC references RFC5234, Appendix B.1 to define "CRLF" as %x0D %x0A.

但是,认识到人们会出于任何目的违反标准,因此存在容忍条款".在 第 19.3 节 中(注意它重新迭代了 正确的顺序):

However, recognizing that people will break the standard for whatever purposes, there is a "tolerance provision" in section 19.3 (note that it re-iterates the correct sequence):

消息头字段的行终止符是序列 CRLF.但是,我们建议应用程序在解析此类标头时,将单个 LF 识别为行终止符并忽略前导 CR.

The line terminator for message-header fields is the sequence CRLF. However, we recommend that applications, when parsing such headers, recognize a single LF as a line terminator and ignore the leading CR.

在较新的RFC7230, § 3.5

尽管起始行和头字段的行终止符是序列 CRLF,但接收者可以将单个 LF 识别为行终止符并忽略任何前面的 CR.

Although the line terminator for the start-line and header fields is the sequence CRLF, a recipient MAY recognize a single LF as a line terminator and ignore any preceding CR.

因此,除非您想成为邪恶或以其他方式违反 RFC 规则,否则请使用 .

Therefore, unless you want to be Evil or otherwise break the RFC's rules, use .

这篇关于HTTP 标头换行样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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