Is the use of Location header in HTTP 202 response RFC-compliant?

前端 未结 4 1466
太阳男子
太阳男子 2020-12-29 22:52

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 heade

相关标签:
4条回答
  • 2020-12-29 23:04

    The RFC admittly is vague on that concept. This means that the spec currently doesn't say how "Location" is used with 202, but on the other hand, it's not a license for libraries to simply replace the status code. So this is definitively a PHP bug.

    0 讨论(0)
  • 2020-12-29 23:09

    From RFC-2616:

    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.

    I think the key here is, "the entity", since the question here is whether we include the status indication in the response headers or in the response body. Almost everywhere an entity is referred to, it seems to imply the response body. For example:

    10.5 Server Error 5xx

    Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents SHOULD display any included entity to the user. These response codes are applicable to any request method.

    I haven't seen a browser ever display response headers to a user. And for 303s:

    10.3.4 303 See Other

    The different URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).

    You won't get a hypertext response in headers.

    However, section 7 is quite clear about what the entity refers to:

    An entity consists of entity-header fields and an entity-body, although some responses will only include the entity-headers.

    I think that in your case, what you are doing is RFC-2616-compliant. However, realistically this all comes down to client implementation. Can the client receiving your 202 response handle a Location: header for a 2xx response? That should be your litmus test for how to respond, and is also the test used to drive standards during their standardization/documentation.

    0 讨论(0)
  • 2020-12-29 23:18

    Finally, I received a response from R. Fielding:

    enter image description here

    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.

    0 讨论(0)
  • 2020-12-29 23:27

    Actually, as per the rfc 7240 http://tools.ietf.org/html/rfc7240#section-4.1 you can send a 202 Status Code along with a Location header. That would be in an asynchronous response, though ,apparently, PHP won't allow you to do so.

    0 讨论(0)
提交回复
热议问题