HTTP服务器超时.应该在什么时候发送 [英] HTTP server timeout. When should it be sent

查看:107
本文介绍了HTTP服务器超时.应该在什么时候发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写小型http服务器,并尝试了解超时问题.

I’m writing small http server and try to understand timeout issues.

RFC7230 没有给出问题的答案是什么条件强制服务器发送超时(408请求超时).客户端发送请求的时间过长是否应该发送?还是在一段时间内未在打开的连接中发送任何内容?逻辑应该是什么?有任何标准或行为模型吗?

RFC7230 don’t give an answer for the question what are conditions that forces server to send timeout (408 Request timeout). Should it be sent when client sends request too long? Or if nothing was sent in opened connection for some time? What the logic should be? Is there any standard or behavioral model?

推荐答案

整个过程将

服务器等待请求->读取请求标头->读取请求正文->准备响应标头->准备响应正文

server wait for a request -> read request header -> read request body -> prepare response header -> prepare response body

因此,如果请求花了很长的时间(例如30秒),则服务器将返回带有代码408请求超时的响应标头

So if the request take to long Ex: 30 seconds, then server will return a response header with code 408 Request timeout

下一种情况是,服务器可以读取整个请求标头和主体并尝试处理该请求,但无法在一定时间内完成,则它将返回504网关超时或503服务不可用.

The next case is when server can read whole request header and body and try to process that request but can not complete in an amount of time then it will return 504 Gateway Timeout or 503 Service Unavailable.

这取决于每种情况.但是规则始终是4xx用于请求错误,5xx用于服务器错误

It will depend of each situation. But the rule is always use 4xx for request errors and 5xx for server errors

此处列出了有关HTTP代码的简短说明: HTTP响应状态码

The short explaination for thoose http code is listed here: HTTP response status codes

这篇关于HTTP服务器超时.应该在什么时候发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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