与text / plain ContentType一起使用的正确换行符是什么? [英] What is the correct newline to use with text/plain ContentType?

查看:919
本文介绍了与text / plain ContentType一起使用的正确换行符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当网络服务器声称ContentType:HTTP响应中的text / plain时,客户端可以假设换行符为\ n或\\\\ n,还有其他内容,还是应该允许两者?



什么标准指定?我在标准中迷茫和困惑。 RFC 2046似乎定义了'普通'子类型,但是引用了RFC 822。



我已经浏览了RFC 822但是我对它是否说CRLF很困惑明确地不允许(在邮件正文中),或者是否应该隐式允许CRLF,因为任何ASCII字符在空白行后是合法的?



< RFC 5322定义了互联网邮件格式,我不确定这是否适用于HTTP(它似乎适用于电子邮件),但它明确指出您应该看到的邮件正文中的唯一CR或LF是CRLF组合..?

解决方案

RFC 2046 第4.1.1节说:



任何MIMEtext子类型的规范形式必须始终代表换行符类似地,MIMEtext中出现的任何CRLF都必须表示换行符。在换行符序列之外使用CR和LF也是forbi dden。



老实说,如果你使用它进行解析或显示,我不会依赖它。大多数Web服务器将从文件扩展名设置内容类型,因此任何扩展名为.txt的Unixy文件都将获得text / plain内容类型(非法,就上述段落而言)。


When a webserver claims ContentType: text/plain in an HTTP response can the client assume newlines are '\n', or '\r\n', something else, or should it allow both?

What standards specify? I am lost and confused among the standards. RFC 2046 appears to define the 'plain' subtype, but there refers to RFC 822.

I've skimmed RFC 822 but I'm confused about whether it is saying CRLF (\r\n) is explicitly not allowed (in the message body), or whether CRLF should implicitly be allowed because any ASCII character is legal after the blank line?

RFC 5322 defines the 'internet message format' and I'm not sure if that applies to HTTP (it seems intended for email), but it specifically says the ONLY CR or LF in the message body you should see is the CRLF combination..?

解决方案

RFC 2046 section 4.1.1 says:

"The canonical form of any MIME "text" subtype MUST always represent a line break as a CRLF sequence. Similarly, any occurrence of CRLF in MIME "text" MUST represent a line break. Use of CR and LF outside of line break sequences is also forbidden."

To be honest though, if you're using this for parsing or display purposes I wouldn't rely on it. Most webservers are going to set the content-type from the file extension, so any Unixy file with a .txt extension is going to get the text/plain content-type (illegally, as far as the paragraph above is concerned).

这篇关于与text / plain ContentType一起使用的正确换行符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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