在HTTP 202中使用Location头是否符合RFC标准? [英] Is the use of Location header in HTTP 202 response RFC-compliant?

查看:156
本文介绍了在HTTP 202中使用Location头是否符合RFC标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的同事讨论了在202 Accepted response中使用Location头的一个很好的概念。



故事开始分析PHP header()函数的行为来自作者(J。Snell)在202 Accepted response中使用Location头给出了一个例子。他错了吗?这就像许多人从RFC 7231中理解这种行为。你能否向我发送有关这一有争议问题的任何参考资料?



Roy: 这个例子是在没有指令的情况下给出的,所以他没有错误
,因为他没有说明这意味着什么。位置可以在任何
消息中发送。这意味着只为某些状态代码定义。



例如,如果他说用户代理会使用
表示Location字段为用户提供状态指示,然后
他本来就错了。这可能是一个好主意,但它不是标准的
部分。



PHP做出错误的假设仅用于201和
3xx响应,但允许这样做,因为它的内部API
不是HTTP;它将流转换为HTTP。



没有争议。为了成为标准的一部分,在
至少两个独立的实现必须显示相同的
行为。在这种情况下,没有。


I have a great conceptual discussion with my coworkers about the use of Location header in 202 Accepted response.

The story began analyzing the behavior of PHP header() function from here. The interesting excerpt:

The second special case is the "Location:" header. Not only does it send this header back to the browser, but it also returns a REDIRECT (302) status code to the browser unless the 201 or a 3xx status code has already been set.

They didn't include 202 status code in this default behavior. It seems like they don't expect that 202 response has a Location and indeed:

header("HTTP/1.1 202");
header("Location: http://example.com");

redirect the client to Location URL. Of course, it is possible to change this behavior with third parameter of header() function but what attracted my attention was: Why they understood that by default 202 is not expected to hold a Location header?

Then I review the RFC looking for the official meaning of 202 status. The interesting excerpt:

The entity returned with this response SHOULD include an indication of the request's current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.

It doesn't explicitly refer to Location header like previous (in the same RFC doc) 201 response does. That would probably be the reason why PHP guys understood that 202 response should not hold Location header. Would a pointer be interpreted as Location header or PHP guys made a wrong assumption? If the standard allow Location header with 202 response: should not be the official documentation more explicit like 201 response definition?

Finally I reviewed the most recently RFC version and find a little change in redaction:

The representation sent with this response ought to describe the request's current status and point to (or embed) a status monitor that an provide the user with an estimate of when the request will be fulfilled.

Again it is not explicit enough to assume that point to means Location header.

In short, after above revisions: Am I being RFC-compliant using Location header with 202 response?

解决方案

Finally, I received a response from R. Fielding:

202 is a success status. The pointer mentioned is just hypertext in the body of the response. A 303 should be sent if you want to use Location to redirect the client to another resource. The result of the redirected request can be a 202.

....Roy

So, the Location header should not be used in 202 Accepted response. The PHP guys did the right interpretation.

Edit March, 2017: Sorry, I forgot to add other messages we exchanged in the same thread at that moment so I am posting now for the record:

me: On the section 4.1 of the RFC 7240 the author (J. Snell) give an example using Location header in 202 Accepted response. Is he wrong? It is like many people understand this behavior from RFC 7231. Can you send me any reference about this controversial issue?

Roy: The example is given without instruction, so he is not wrong because he doesn't say what it means. Location can be sent in any message. What it means is only defined for certain status codes.

For example, if he had said that the user agent would make use of that Location field to provide a status indicator to the user, then he would have been wrong. It might be a good idea, but it isn't part of the standard.

PHP makes a wrong assumption that Location is only used in 201 and 3xx responses, but it is allowed to do so because its internal API is not HTTP; it translates the stream to HTTP instead.

There is no controversy. In order to be part of the standard, at least two independent implementations would have to show the same behavior. In this case, none do.

这篇关于在HTTP 202中使用Location头是否符合RFC标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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