HTTP Status 411 - Length Required

Der HTTP-Status-Code 411 Length Required signalisiert, dass der Server den Request ohne Content-Length Header nicht akzeptiert. Typisch bei POST/PUT-Requests mit Body. Server benötigt Vorab-Information über Body-Größe für Resource-Allocation oder Size-Validation.

Typ

Response-Status-Code

Syntax

Der Status Code wird zurückgegeben bei fehlendem Content-Length Header.

http
HTTP/1.1 411 Length Required

Direktiven

Der 411 Length Required Status Code wird verwendet, wenn Content-Length fehlt.

Content-Length Required
Server weigert sich, Request ohne Content-Length Header zu verarbeiten. Auch bei chunked Transfer Encoding kann Server 411 zurückgeben, wenn er definite Length benötigt.
Upload Size Validation
Server will Body-Größe vor Empfang prüfen (Quota-Checks, Max-Upload-Size-Validation). Ohne Content-Length kann Server nicht vorab validieren.
Resource Allocation
Server muss Speicher oder Disk-Space für Request Body allokieren. Ohne bekannte Größe kann Server nicht effizient Resources planen.

Beispiele

Nachfolgend finden Sie praktische Anwendungsbeispiele für Status 411.

Beispiel 1 Missing Content-Length on Upload

http
POST /api/files HTTP/1.1
Host: api.example.com
Content-Type: application/octet-stream
Transfer-Encoding: chunked

HTTP/1.1 411 Length Required
Content-Type: application/json

{
  "error": "length_required",
  "message": "Content-Length header is required for file uploads",
  "reason": "Server needs to validate upload size against quota before accepting data"
}

Beispiel 2 With Content-Length Success

http
POST /api/files HTTP/1.1
Host: api.example.com
Content-Type: application/octet-stream
Content-Length: 1048576

[1MB binary data]

HTTP/1.1 201 Created
Location: /api/files/file-abc-123

Beispiel 3 Size Limit Pre-Check

http
PUT /api/documents/doc-1 HTTP/1.1
Host: api.example.com
Content-Type: application/pdf

[PDF data without Content-Length]

HTTP/1.1 411 Length Required
Content-Type: application/json

{
  "error": "length_required",
  "message": "Content-Length required for size validation",
  "max_file_size": 52428800,
  "reason": "Server must validate size before allocating storage"
}

Length Required Flow

411 Length Required bei fehlendem Content-Length Header

Vorteile für die Systemarchitektur

  • Quota Pre-Validation: Server kann Quota-Limits prüfen bevor Upload startet. Spart Bandwidth wenn User Quota exhausted ist, verhindert partial Uploads.
  • Resource Planning: Server kann Speicher, Disk-Space oder Processing-Resources effizient allokieren basierend auf bekannter Body-Größe. Vermeidet Over-Allocation oder Resource-Exhaustion.
  • DoS Prevention: Schützt gegen unbegrenzte Uploads ohne Size-Information. Server kann Requests mit excessive Size ablehnen bevor Daten übertragen werden.

Spezifikation

RFC 9110, Section 15.5.12 – HTTP Semantics https://www.rfc-editor.org/rfc/rfc9110.html#name-411-length-required

Weitere Spezifikationen

Content-Length Header, POST Method