在分块传输编码中发送响应并指示在已经发送一些数据之后发生的错误 [英] Response sent in chunked transfer encoding and indicating errors happening after some data has already been sent

查看:151
本文介绍了在分块传输编码中发送响应并指示在已经发送一些数据之后发生的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以分块传输编码格式向客户端发送大量数据。

I am sending large amount of data in my response to the client in chunked transfer encoding format.

在撰写回复期间,我应该如何处理中途发生的任何错误?

How should I be dealing with any errors that occur midway during writing of the response?

我想知道是否有任何HTTP规范推荐的做法,让客户知道确实响应不是一个成功但服务器遇到了一些问题。

I would like to know if there is any HTTP Spec recommended practice regarding this for clients to know that indeed the response is not a successful one but that the server ran into some issue.

推荐答案

一旦开始向客户端发送HTTP标头,就无法发送任何其他信息。您必须完成发送您要发送的响应,即分块数据和相关标头。如果在中途发生错误,则无法向客户端报告该错误。您所能做的就是关闭连接。客户端没有收到所有标头,或者在响应结束时没有收到终止0长度的块。无论哪种方式都足以让客户端知道服务器在发送过程中遇到错误。

Once you have started sending the HTTP headers to the client, you can't send anything else. You have to finish sending the response you intended to send, ie the chunked data and associated headers. If an error occurs midway through that, there is no way to report that error to the client. All you can do is close the connection. Either the client does not receive all of the headers, or it does not receive the terminating 0-length chunk at the end of the response. Either way is enough for the client to know that the server encountered an error during sending.

这篇关于在分块传输编码中发送响应并指示在已经发送一些数据之后发生的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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