4

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

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?

Community
  • 1
  • 1
Yura
  • 969
  • 14
  • 33

1 Answers1

3

The whole process would be

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

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

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.

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

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

Dung Le
  • 104
  • 3
  • 4
    You should not return a HTTP 408 if the connection is not idle. For instance, if the client is uploading content and it takes more than 30 seconds, then you are not supposed to return 408, since the connection is still active. You need to monitor whether or not something is happening on the line. – oligofren Jun 07 '21 at 23:07