HTTP响应可以省略Reason-Phrase吗? [英] Can an HTTP response omit the Reason-Phrase?

查看:1291
本文介绍了HTTP响应可以省略Reason-Phrase吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正常的HTTP响应如下所示:

A normal HTTP response looks like:

HTTP/1.0 200 OK

是否可以省略 RFC 调用 Reason-Phrase ?类似于:

Is it OK to omit what the RFC calls the Reason-Phrase? Something like:

HTTP/1.0 200

RFC说:

Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
Reason-Phrase  = *<TEXT, excluding CR, LF>

我理解为:


  • 空字符串可以用于原因 - 短语

  • 但是状态代码之后应该有一个空格

所以以下内容有效:

HTTP-Version SP Status-Code SP CRLF

我是否正确理解RFC?

Do I understand the RFC correctly?

推荐答案

如果您将 * 读作零个或多个字符,就像在正则表达式中一样。

It looks that way, if you read the * as 'zero or more characters', like in regular expressions.

如果您阅读 Notational Convention


* rule

元素前面的字符*表示重复。完整形式是< n> *< m>元素,表示至少< n>。并且至多< m>
出现的元素。默认值为0和无穷大,因此
*(元素)允许任何数字,包括零; 1 *元素要求
至少一个;并且1 * 2element允许一个或两个。

所以虽然它不是正则表达式,但意思是基本相同。在这种情况下,没有尾随数字的星号表示可以有0或更多文本。奇怪的方式,但似乎你是对的。

So although it's not regex, the meaning is essentially the same. The asterix, not having a trailing number in this case, means that there can be "0 or more" "texts". Odd way to put it, but it seems you're right.

严格地说,空间必须的,尽管我认为如果没有什么可以分开,可以省略分隔符。但是,它可能会杀死具有严格实现的客户端,如果他们只是在空格上拆分此字符串并尝试读取描述应该在的元素。但话说回来,那些客户应该使用一些防御性程序来捕捉这种情况。 ;)

Strictly speaking, the space is mandatory, although I'd think a separator might be omitted if there's nothing to separate. It might kill clients that have a strict implementation, though, if they just split this string on the spaces and try to read the element in which the description should be. But then again, those clients should have used some defensive programming to catch that situation. ;)

RFC 表示它可以是任何文本,只要它是人类可读的问题描述。此文本很重要,因为客户端可能无法理解状态代码的确切含​​义,因此可能需要向用户显示文本。所以即使你可以省略它,我个人也不会。

The RFC does say that it can be any text, as long as it is a human readable description of the problem. This text is important, because the client may not understand the exact meaning of the status code, so it may need to display the text to the user. So even though you can omit it, I personally wouldn't.

这篇关于HTTP响应可以省略Reason-Phrase吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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