gpt4 book ai didi

http - 服务器在收到整个请求之前发送 HTTP 响应是否可以接受?

转载 作者:可可西里 更新时间:2023-11-01 15:04:24 24 4
gpt4 key购买 nike

考虑一个大的 HTTP 请求:

POST /upload HTTP/1.1
Content-Type: multipart/form-data
Content-Length: 1048576

...

客户端现在开始上传 1 兆字节的数据,这可能需要一段时间。但是,服务器确定需要 HTTP 授权,因此它决定使用 HTTP 401 Unauthorized 进行响应。

服务器必须等到它收到整个请求(IE,headers + CRLF CRLF + Content-Length 字节)才能响应吗?

实际上,这种行为会破坏任何浏览器吗?浏览器会继续上传文件,还是会在收到“过早”响应时停止传输?

更重要的是,在这种情况下,他们是否能够成功验证并重新开始上传(使用凭据),或者像这样切断上传是不可靠的?

最佳答案

查看定义协议(protocol)的 RFC 2616,在第 8.2.2 节监视错误状态消息的连接中,它指出

An HTTP/1.1 (or later) client sending a message-body SHOULD monitor the network connection for an error status while it is transmitting the request. If the client sees an error status, it SHOULD immediately cease transmitting the body.

所以我会说使用您可以跳入发送 401 错误。然后查看 10.4.2 401 Unauthorized

The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.47) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field

声明客户端可以使用合适的凭据重试。

不过,我还没有进行任何实验来了解浏览器的实际性能。

关于http - 服务器在收到整个请求之前发送 HTTP 响应是否可以接受?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14250991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com