408 Request Timeout
Description
The 408 Request Timeout
status code indicates that the server did not receive a complete request from the client within the time that the server was prepared to wait. The client may repeat the request without modifications at any later time.
This status code is commonly used when: - A client starts sending a request but doesn't complete it within the server's timeout period - A client establishes a connection but doesn't send any request data - Network issues cause delays in transmitting the complete request - The client's request takes too long to process or upload
The 408 Request Timeout
status helps servers manage resources efficiently by closing connections that aren't actively being used, preventing potential denial-of-service situations where too many idle connections are maintained.
Syntax
The server responds with a 408 Request Timeout
status:
HTTP/1.1 408 Request Timeout
Connection: close
Content-Type: text/html
Content-Length: [length in bytes]
[Response body explaining the timeout]
Examples
Idle Connection Example
A client establishes a connection but doesn't send a request:
Server Response (after timeout period):
HTTP/1.1 408 Request Timeout
Connection: close
Content-Type: text/html
Content-Length: 243
<!DOCTYPE html>
<html>
<head>
<title>Request Timeout</title>
</head>
<body>
<h1>408 Request Timeout</h1>
<p>The server timed out waiting for the request.</p>
<p>Please retry your request at a later time.</p>
</body>
</html>
Large File Upload Example
A client begins uploading a large file but the upload takes too long:
Client Request (partial):
POST /upload HTTP/1.1
Host: files.example.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Length: 104857600
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="large-video.mp4"
Content-Type: video/mp4
[Partial file data...]
Server Response (after timeout period):
HTTP/1.1 408 Request Timeout
Connection: close
Content-Type: application/json
Content-Length: 183
{
"error": "Request Timeout",
"message": "The server timed out waiting for the complete file upload",
"max_upload_time": "30 seconds",
"upload_recommendations": "Try compressing the file or using our chunked upload API"
}
Slow Client Example
A client with a slow connection takes too long to send the complete request:
Server Response (after timeout period):
HTTP/1.1 408 Request Timeout
Connection: close
Retry-After: 60
Content-Type: text/plain
Content-Length: 128
Request timed out. The server did not receive the complete request within the allotted time. Please try again when you have a faster connection.
Summary
The 408 Request Timeout
status code is an important mechanism for servers to manage their resources efficiently. By closing connections that aren't actively being used or that are taking too long to complete, servers can prevent resource exhaustion and maintain availability for other clients. This status code provides clear feedback to clients that their request wasn't processed due to timing constraints rather than an error in the request itself, allowing them to retry when conditions improve. In high-traffic environments, proper timeout handling is crucial for maintaining system stability and responsiveness.