408 Request Timeout
Fault: Client
TL;DR
Client took too long to send the complete request.
The server timed out waiting for the request.
What This Error Means
The server timed out waiting for the request.
Client took too long to send the complete request.
Common Causes
- Slow network connection
- Large file upload interrupted
- Client not sending data
How to Fix It (For Visitors)
- Retry the request
- Check internet connection
- Try with smaller files
How to Fix It (For Developers/Admins)
- Increase timeout settings
- Implement chunked upload
- Add retry logic
- Check network latency
Code Examples
Here's how to return a 408 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Request Timeout"}), 408
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(408).json({ message: 'Request Timeout' });
});
PHP
<?php
http_response_code(408);
header('Content-Type: application/json');
echo json_encode(['message' => 'Request Timeout']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(408)
json.NewEncoder(w).Encode(map[string]string{
"message": "Request Timeout",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Request Timeout");
return ResponseEntity.status(408).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 408
json message: 'Request Timeout'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 7231 Section 6.5.7.