"http:多个响应.WriteHeader调用"的不良影响是什么? [英] What's the bad effect of "http: multiple response.WriteHeader calls"?

查看:57
本文介绍了"http:多个响应.WriteHeader调用"的不良影响是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我发现"http:多个响应.WriteHeader调用"例外,但服务器的运行情况仍然良好.此异常不会导致我的服务器出现恐慌或怪异的行为.

我进行了很多搜索,但只找到了解决该问题的方法.没有文档描述异常的不良影响.有人可以帮助我找到为什么"http:多重响应.WriteHeader调用"是一个异常,以及它引起的不良影响是什么?预先感谢.

更新

我已在

多次调用 WriteHeader 时,它只打印日志,然后不执行任何操作.似乎多次调用 WriteHeader 不会导致服务器异常运行.

解决方案

在将响应标头发送到客户端之前,您只能编写一次.因为您的代码在发送给客户端之后正在尝试编写响应标头,所以客户端将永远不会看到您尝试发送的最终响应.

您可能遇到一个错误,即客户端得到了您后来修改的错误响应,或者您遇到了一个错误,即在编写了正确的响应头之后执行了错误的代码.无论哪种方式,它都是一个错误.

My server behaves well though I find the exception of "http: multiple response.WriteHeader calls". This exception doesn't cause my server panic or behaving weirdly.

I have searched a lot but only found how to solve this problem. There's no doc describing the bad effects of the exception. Could someone help me find why "http: multiple response.WriteHeader calls" is an exception and what the bad effects are that it causes? Thanks in advance.

UPDATE

I have read the source code here:

When calling WriteHeader multitimes,it only prints a log and then does nothing. It seems that calling WriteHeader multitimes doesn't cause the server behaves weiredly.

解决方案

You can only write a response header once before it is sent to the client. Because your code is attempting to write a response header after it has been sent to the client, the client will never see the final response you are trying to send.

You either have a bug where the client is getting the incorrect response which you later revised, or you have a bug where you are executing the wrong code after the correct response header has been written. Either way it's a bug.

这篇关于"http:多个响应.WriteHeader调用"的不良影响是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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