问题描述
说明:我正在用C ++编写HTTP服务器.我确切地知道我已经收到了多少数据,并且正在将HTTP请求分块地解析.因此,在我收到整个请求之前,我可能会知道该方法是什么.
Clarification: I'm writing a HTTP server in C++. I know exactly how much data I've received and I'm parsing the HTTP request in chunks. So, it's possible for me to know what the method is before I've received the entire request.
请考虑以下情形:我收到一个HTTP请求,其方法设置为"DO_WORK".不支持此功能(仅作为示例),我应该回复405(不支持该方法).但是,我多久可以这样做?
Consider the following scenario: I receive a HTTP request with the method set to 'DO_WORK'. This isn't supported (just an example), and I should reply with a 405 (method not supported). However, how soon can I do so?
我应该等到收到全部请求后再发送回复吗?
Should I wait until I have received the entire request before I send a response?
推荐答案
除非有技术上的原因禁止这样做,否则您通常可以在准备就绪后立即发送答复,因为客户端直到收到答复才阅读已完整发送其请求.但是,除非您在发送回复后断开连接,否则您必须阅读完整的请求.
Unless there is a technical reason prohibiting it, you can generally send the reply as soon as you are ready to, as the client will not read it until it has finished sending its request in full. You do, however, have to read the full request unless you disconnect after sending the reply.
这篇关于我可以在完成接收之前回复HTTP请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!