HTTP 411 Length Required indicates the server requires the Content-Length header to be present in the request. The server refuses to accept the request without a defined content length, typically because it needs to allocate resources or enforce size limits before receiving the body. This is increasingly rare as chunked transfer encoding (Transfer-Encoding: chunked) allows streaming without knowing the total size upfront.
Response includes the status code, standard headers (including Content-Type), and a small diagnostic JSON body describing the request and returned status.
Simulator URL (copy in the app after load — not a normal link):
https://httpstatus.com/api/status/411
Example request:
curl -i "https://httpstatus.com/api/status/411"The request did not specify the length of its content.
On this code, Inspector focuses on semantics, headers, and correctness warnings that commonly affect clients and caches.
HTTP 411 Length Required has specific technical implications for API design, caching, and client behavior. Understanding the precise semantics helps distinguish it from similar status codes and implement correct error handling. The response should include a descriptive body following a consistent error schema (like RFC 7807 Problem Details) so clients can programmatically handle the error.
// Handle 411 Length Required in Express
app.use((err, req, res, next) => {
if (err.status === 411) {
return res.status(411).json({
type: 'https://api.example.com/errors/length-required',
title: 'Length Required',
status: 411,
detail: err.message
});
}
next(err);
});from fastapi import HTTPException
# Raise 411 Length Required
raise HTTPException(
status_code=411,
detail={
'type': 'length_required',
'message': 'Descriptive error for 411 Length Required'
}
)// Spring Boot 411 Length Required handling
@ExceptionHandler(CustomLengthRequiredException.class)
public ResponseEntity<ErrorResponse> handleLengthRequired(
CustomLengthRequiredException ex) {
return ResponseEntity.status(411)
.body(new ErrorResponse("Length Required", ex.getMessage()));
}// Return 411 Length Required
func errorHandler(w http.ResponseWriter, message string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(411)
json.NewEncoder(w).Encode(map[string]any{
"status": 411,
"error": "Length Required",
"message": message,
})
}