HTTP Content-Location Header

Der HTTP-Header Content-Location ist ein Response-Header, der die direkte URL der zurückgegebenen Ressource angibt. Er wird verwendet, wenn die URL der Response von der Request-URL abweicht, etwa bei Content-Negotiation oder nach POST-Operationen.

Typ

Response-Header

Syntax

Der Header enthält eine absolute oder relative URL zur Ressource.

http
Content-Location: /api/products/42/de
Content-Location: https://cdn.example.com/files/abc123.json

Direktiven

Der Content-Location-Header spezifiziert die URL der tatsächlich zurückgegebenen Ressource.

url
Eine absolute oder relative URL, die auf die spezifische Repräsentation der Ressource zeigt. Kann sich von der Request-URL unterscheiden.
scope
Gibt an, wo die zurückgegebene Ressource eigenständig abrufbar ist, unabhängig von der ursprünglichen Anfrage-URL.

Beispiele

Nachfolgend finden Sie praktische Anwendungsbeispiele für den Content-Location-Header.

Beispiel 1 Content Negotiation

http
GET /api/products/42 HTTP/1.1
Accept-Language: de

HTTP/1.1 200 OK
Content-Type: application/json
Content-Location: /api/products/42/de
Content-Language: de

{"name": "Laptop", "preis": 999}

Beispiel 2 POST mit Created Resource

http
POST /api/documents HTTP/1.1
Content-Type: application/json

{"title": "Report"}

HTTP/1.1 201 Created
Location: /api/documents/789
Content-Location: /api/documents/789
Content-Type: application/json

{"id": 789, "title": "Report", "created": "2025-10-01T14:30:00Z"}

Beispiel 3 CDN Redirect

http
GET /api/images/logo.png HTTP/1.1

HTTP/1.1 200 OK
Content-Location: https://cdn.example.com/img/logo-v2.png
Content-Type: image/png

[Binary Image Data]

Content Location Resolution Flow

Content-Location bei sprachbasierter Content-Negotiation

Vorteile für die Systemarchitektur

  • Caching-Optimierung: Caches können die spezifische Variante unter der angegebenen URL cachen, unabhängig von Request-Parametern
  • HATEOAS-Unterstützung: Clients erhalten direkte Links zu spezifischen Ressourcen-Repräsentationen für API-Navigation
  • Transparente Content-Negotiation: Entwickler sehen sofort, welche konkrete Variante einer Ressource zurückgegeben wurde

Spezifikation

RFC 9110, Section 8.7 – HTTP Semantics https://www.rfc-editor.org/rfc/rfc9110.html#name-content-location

Weitere Spezifikationen

Location Header, HTTP Status 200 - OK