HTTP Expires Header

Typ

Der Expires-Header ist ein HTTP-Response-Header, mit dem der Server das absolute Datum und die Zeit angibt, nach der eine Response als veraltet gilt.

Syntax

Der Header enthält einen Zeitstempel im HTTP-Date-Format nach RFC 5322.

http
Expires: Wed, 01 Oct 2025 12:00:00 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT

Direktiven

Der Expires-Header verwendet ein HTTP-Date-Format:

http-date
Absoluter Zeitstempel im IMF-fixdate-Format (Internet Message Format). Zeitzone ist immer GMT. Format: Day, DD Mon YYYY HH:MM:SS GMT.
already-expired
Datum in der Vergangenheit (z.B. Thu, 01 Jan 1970 00:00:00 GMT) signalisiert, dass Response nicht gecached werden soll.
cache-control-precedence
Wenn Cache-Control: max-age vorhanden ist, überschreibt dieser den Expires-Header. Cache-Control hat Vorrang.

Beispiele

API-Response mit absolutem Expiration-Zeitpunkt

Eine API liefert Produktdaten mit festem Ablaufzeitpunkt:

http
GET /api/v1/products/12345 HTTP/1.1
Host: api.example.com
Accept: application/json

Der Server setzt Expires auf Mitternacht UTC:

http
HTTP/1.1 200 OK
Date: Wed, 01 Oct 2025 10:25:00 GMT
Expires: Thu, 02 Oct 2025 00:00:00 GMT
Content-Type: application/json

{
  "product_id": "12345",
  "name": "Premium Widget",
  "price": 99.99,
  "valid_until": "2025-10-02T00:00:00Z"
}

Cache berechnet Freshness: 13 Stunden 35 Minuten verbleibend.

API verwendet Expires für veraltete Responses

Eine API markiert Response als bereits abgelaufen:

http
GET /api/v1/realtime/stock-prices HTTP/1.1
Host: finance.example.com
http
HTTP/1.1 200 OK
Date: Wed, 01 Oct 2025 10:25:00 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json

{
  "symbol": "AAPL",
  "price": 175.50,
  "timestamp": "2025-10-01T10:25:00Z"
}

Caches speichern die Response nicht, da bereits abgelaufen.

Cache-Control überschreibt Expires

Eine API verwendet beide Header, Cache-Control hat Vorrang:

http
GET /api/v1/config/settings.json HTTP/1.1
Host: api.example.com
http
HTTP/1.1 200 OK
Date: Wed, 01 Oct 2025 10:25:00 GMT
Cache-Control: public, max-age=3600
Expires: Wed, 01 Oct 2025 11:30:00 GMT
Content-Type: application/json

{
  "api_version": "v1",
  "features": ["webhooks", "rate_limiting"]
}

Cache verwendet max-age=3600 (1 Stunde ab Date), ignoriert Expires (1 Stunde 5 Minuten).

Expires-vs-Cache-Control-Flow

Der Ablauf der Cache-Freshness-Bestimmung mit Expires und Cache-Control.

plantuml
@startuml
actor Client
participant "Cache (CDN)" as Cache
participant "API Server" as API

Client -> Cache: GET /api/v1/resource
Cache -> API: Cache miss\nForward request

API -> API: Generate response\nDate: 10:00:00 GMT\nExpires: 11:00:00 GMT\n(1 hour freshness)
API --> Cache: 200 OK\nDate: 10:00:00 GMT\nExpires: 11:00:00 GMT

Cache -> Cache: Store response\nFreshness: 1 hour\n(Expires - Date)
Cache --> Client: 200 OK\n[data]

Client -> Cache: GET /api/v1/resource\n(10:30:00 GMT)
Cache -> Cache: Check freshness\nCurrent: 10:30:00\nExpires: 11:00:00\nStill fresh (30 min left)
Cache --> Client: 200 OK\nAge: 1800\n[cached data]

Client -> Cache: GET /api/v1/resource\n(11:15:00 GMT)
Cache -> Cache: Check freshness\nCurrent: 11:15:00\nExpires: 11:00:00\nStale (expired 15 min ago)
Cache -> API: Revalidate\nIf-None-Match: "etag-v1"

alt Content unchanged
  API --> Cache: 304 Not Modified\nExpires: 12:00:00 GMT
  Cache -> Cache: Update Expires\nRe-fresh response
  Cache --> Client: 200 OK\n[cached data]
else Content changed
  API --> Cache: 200 OK\nNew content\nExpires: 12:00:00 GMT
  Cache -> Cache: Update cache
  Cache --> Client: 200 OK\n[new data]
end
@enduml

Vorteile für die Systemarchitektur

  • Ermöglicht absolute Ablaufzeitpunkte für zeitbasierte Ressourcen (z.B. Tagespreise)
  • Einfaches Caching-Konzept ohne komplexe relative Zeit-Berechnungen
  • HTTP/1.0-kompatibel für Legacy-Systeme und ältere Proxies
  • Kombinierbar mit Cache-Control für moderne und Legacy-Cache-Unterstützung
  • Nützlich für Ressourcen mit natürlichem Ablaufzeitpunkt (z.B. Event-Tickets)

Spezifikation

Der Expires-Header ist in RFC 9111 Section 5.3 (HTTP Caching) definiert.

Weitere Spezifikationen

Cache-Control Header, Last-Modified Header