4114xx
4xx — Client Error
Length Required
The server refuses to accept the request without a defined Content-Length.
What it means
The HTTP 411 Length Required client error response code indicates that the server refuses to accept the request without a defined `Content-Length` header.
This usually happens when the client is streaming data (chunked transfer encoding) to a server that requires knowing the exact file size upfront.
How it works
- 1The client sends a POST/PUT request with a body, but omits the Content-Length header.
- 2The server requires knowing how large the payload is before allocating memory.
- 3The server rejects the request with 411.
Why you're seeing this
- • The HTTP client failed to include a Content-Length header.
How to fix it
- • Calculate the size of your payload before sending it, and include `Content-Length: <bytes>` in your request.
Framework Implementations
Express.js
app.post('/upload', (req, res, next) => {
if (!req.headers['content-length']) {
return res.status(411).send('Length Required');
}
next();
});Real-Life Scenarios
Use this when your API cannot safely process streams and must allocate an exact amount of memory or validate file sizes before reading the stream.
Strict Upload Limits
A server allows 5MB uploads. It demands a Content-Length header so it can reject massive files instantly, rather than reading 10GB of a stream before throwing an error.
HTTP Transaction
1. Client Request
POST /upload HTTP/1.1 Transfer-Encoding: chunked (data)
2. Server Response
HTTP/1.1 411 Length Required Content-Type: text/plain Content-Length header is missing.
SEO Implications
None.