HTTP/1.0 响应是否需要 Content-Length 标头? [英] Is the Content-Length header required for a HTTP/1.0 response?

查看:26
本文介绍了HTTP/1.0 响应是否需要 Content-Length 标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTTP/1.0 响应是否需要 Content-Length 标头?HTTP 规范提到它是请求所必需的,但没有提及任何关于响应的内容:

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 the response:

http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#Content-Length

所有 HTTP/1.0 都需要有效的 Content-Length 字段值请求包含实体主体的消息.

A valid Content-Length field value is required on all HTTP/1.0 request messages containing an entity body.

如果响应不需要,那么当响应大于 1MB 时,客户端如何读取响应?

If it is not required for the response, how does the client read the response when it's larger than 1MB?

推荐答案

规范的第 10.4 节(您链接到的)没有说明响应本身的要求,而是链接到 第7.2.2节,指定服务器可以指示长度包含实体主体的响应由

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

  • 发送 Content-Length 标头,或
  • 在整个响应发送完毕后关闭连接.

第 7.2 节表示对 HEAD 请求和 1xx、204 或 304 响应的响应不应包含实体主体,因此不需要包含 Content-Length 标头;和

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

所有其他响应必须包含一个实体主体或一个定义为零 (0) 值的 Content-Length 标头字段.

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

所以回答这个问题:当没有收到Content-Length时,客户端一直读取直到服务器关闭连接.

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

这篇关于HTTP/1.0 响应是否需要 Content-Length 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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