HTTP Status 417 - Expectation Failed

Der HTTP-Status-Code 417 Expectation Failed signalisiert, dass Server die im Expect-Request-Header angegebene Expectation nicht erfüllen kann. Hauptanwendung ist Ablehnung von Expect: 100-continue Requests bei Large-File-Uploads. Server verhindert Transfer von Request-Body wenn Verarbeitung nicht möglich ist.

Typ

Response-Status-Code

Syntax

Der Status Code wird zurückgegeben bei nicht erfüllbarer Expect-Header-Expectation.

http
HTTP/1.1 417 Expectation Failed

Direktiven

Der 417 Expectation Failed Status Code wird bei Expect-Header-Ablehnung verwendet.

Expect 100-continue Rejection
Client sendet Expect: 100-continue Header bei Large-Upload, Server kann Request nicht verarbeiten (z.B. Authentication Failed, Insufficient Storage, Unsupported Content-Type). 417 verhindert Body-Transfer.
Early Upload Prevention
Server prüft Request-Headers bevor Body übertragen wird. Spart Bandwidth wenn Upload ohnehin abgelehnt werden würde (z.B. File zu groß, falscher Content-Type, fehlende Permissions).
Expectation Extension Unsupported
Falls Client custom Expectation-Extension verwendet, die Server nicht implementiert hat. Server signalisiert, dass Expectation nicht unterstützt wird.

Beispiele

Nachfolgend finden Sie praktische Anwendungsbeispiele für Status 417.

Beispiel 1 Authentication Required Before Upload

http
POST /api/uploads HTTP/1.1
Host: api.example.com
Content-Type: video/mp4
Content-Length: 524288000
Expect: 100-continue

HTTP/1.1 417 Expectation Failed
Content-Type: application/json
WWW-Authenticate: Bearer realm="api"

{
  "error": "authentication_required",
  "message": "Upload requires authentication",
  "details": "Include Authorization header with valid Bearer token"
}

Beispiel 2 File Size Exceeds Quota

http
PUT /api/documents/report.pdf HTTP/1.1
Host: storage.example.com
Content-Type: application/pdf
Content-Length: 104857600
Expect: 100-continue
Authorization: Bearer token123

HTTP/1.1 417 Expectation Failed
Content-Type: application/json

{
  "error": "quota_exceeded",
  "message": "Upload would exceed storage quota",
  "quota_remaining": 52428800,
  "requested_size": 104857600
}

Beispiel 3 Unsupported Content Type

http
POST /api/images HTTP/1.1
Host: cdn.example.com
Content-Type: image/webp
Content-Length: 2097152
Expect: 100-continue

HTTP/1.1 417 Expectation Failed
Content-Type: application/json

{
  "error": "unsupported_content_type",
  "message": "Content-Type image/webp not supported",
  "supported_types": ["image/jpeg", "image/png", "image/gif"]
}

Expect 100-continue Flow mit Rejection

417 Expectation Failed verhindert unnötigen Upload-Body-Transfer

Vorteile für die Systemarchitektur

  • Bandwidth Optimization: 417 verhindert Transfer von großen Request-Bodies wenn Server Request ohnehin ablehnen würde. Spart Bandwidth und Upload-Zeit für Client und Server.
  • Early Error Detection: Server validiert Headers (Auth, Content-Type, Quotas) bevor Body-Transfer beginnt. Client erfährt sofort von Problemen statt nach langem Upload zu scheitern.
  • Resource Protection: Server kann Uploads basierend auf Authentication, Authorization, Quotas oder Content-Policies ablehnen bevor Storage-Resources belegt werden. Verhindert DoS durch Large-Upload-Requests.

Spezifikation

RFC 9110, Section 15.5.18 – HTTP Semantics https://www.rfc-editor.org/rfc/rfc9110.html#name-417-expectation-failed

Weitere Spezifikationen

Expect Header, HTTP Status 100 - Continue