提前关闭与浏览器的连接并返回响应状态
我正在项目中实现一个自定义 IHttpModule,它过滤文件上传并提供上传状态。 我希望自定义模块尽早关闭连接(不想接收对方发送的所有数据,允许很大,节省传入带宽)。
是否可以使用 HTTP 协议?
我尝试发送“ContentLength:0”和“Connection:close”标头,刷新响应,关闭连接(HttpWorkerRequest.CloseConnection)。
workerRequest.SendStatus(400, "Bad request");
workerRequest.SendKnownResponseHeader(HttpWorkerRequest.HeaderContentLength, "0");
workerRequest.SendKnownResponseHeader(HttpWorkerRequest.HeaderConnection, "close");
workerRequest.FlushResponse(false);
workerRequest.CloseConnection();
((HttpApplication)sender).CompleteRequest();
浏览器/Firefox 响应显示“连接重置”错误消息。 没有任何从服务器接收任何数据/标头/状态的迹象。
提前致谢。
I am implementing a custom IHttpModule in a project, which filter file uploading and provide upload status.
I want the custom module to close the connection early (don't want to receive all the data the other side send, which is allowed to be big, save the incoming bandwidth).
Is it a possibility using HTTP protocol?
I tried sending "ContentLength: 0" and "Connection: close" header, flush the response, close the connection (HttpWorkerRequest.CloseConnection).
workerRequest.SendStatus(400, "Bad request");
workerRequest.SendKnownResponseHeader(HttpWorkerRequest.HeaderContentLength, "0");
workerRequest.SendKnownResponseHeader(HttpWorkerRequest.HeaderConnection, "close");
workerRequest.FlushResponse(false);
workerRequest.CloseConnection();
((HttpApplication)sender).CompleteRequest();
The browser/firefox response is displaying the "Connection reset" error message.
Without any sign of receiving any data/header/status from the server.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http 客户端仅在完成发送数据后才期望响应。您应该修改客户端以发出多个小尺寸请求,以便可以向其发送响应,而不是让服务器关闭连接(这将不起作用,并且正如您已经测试过的那样不起作用)。
检查 http://slfileupload.codeplex.com/ 获取通常如何完成的示例。
An http client expects response only after it has completed sending the data. You should modify the client to make multiple requests of small sizes so a response can be sent to it instead of having server close the connection (which will not work and isn't working as you've tested already).
Check the http handler implemented in http://slfileupload.codeplex.com/ for a sample of how it is typically done.