Is the Content-Length header required for a HTTP/1.0 response?

后端 未结 1 1260
北荒
北荒 2020-12-03 02:17

Is the Content-Length header required for a HTTP/1.0 response? The HTTP spec mentions that it is required for the request, but doesn\'t mention anything about t

相关标签:
1条回答
  • 2020-12-03 02:54

    Section 10.4 of the spec (which you linked to) doesn't say anything about requirements on responses itself, but instead links to section 7.2.2, which specifies that the server can indicate the length of a response containing an entity body by

    • sending a Content-Length header, or
    • closing the connection when the entire response has been sent.

    Section 7.2 says that responses to HEAD requests, and 1xx, 204 or 304 responses, should not include an entity body, and therefore need not include a Content-Length header; and

    All other responses must include an entity body or a Content-Length header field defined with a value of zero (0).

    So to answer the question: When no Content-Length is received, the client keeps reading until the server closes the connection.

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