且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

服务器仅从请求中读取标头时,Http客户端未收到任何响应

更新时间:2022-05-08 22:29:08

如果在仍有未读数据的情况下关闭服务器上的套接字,则会导致客户端连接重置错误.因为您没有阅读完整的请求,所以在这里发生这种情况.如果尚未读取服务器的完整响应,则该错误将向用户显示.

If you close a socket at the server while there are still unread data it will result in a connection reset error at the client. This happens here since you don't read the full request. This error will be exposed to the user if the full response from the server was not read yet.

如果您发送的响应内容为 content-length ,然后是完整的正文,则客户端将读取完整的响应,因此错误将被忽略.相反,如果您既不发送 content-length 也不使用分块编码,则客户端将期望响应以适当的TCP连接结束而结束.在这种情况下,连接重置将传播给用户,因为尚未(正确)读取服务器的完整响应.

If you send the response with a content-length and then the full body then the client will have read the full response and thus the error will be ignored. If instead you send neither content-length nor use chunked encoding the client will expect the response to end with a proper close of the TCP connection. In this case the connection reset will be propagated to the user since the full response from the server was not (properly) read yet.