nginx/nginx

Improve handling of Age header with $upstream_cache_age

Open

#1.234 geöffnet am 31. März 2026

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (1 zugewiesene Person)C (7.903 Forks)batch import
enhancementfeaturegood first issuerefined

Repository-Metriken

Stars
 (30.331 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 27T 8h) (17 gemergte PRs in 30 T)

Beschreibung

Feature Overview

A new variable $upstream_cache_age was introduced to reflect response age, including:

  • Time spent in cache
  • Upstream response age from the Age header
  • If not cached, it reflects the upstream Age header directly

This enables use cases aligned with the HTTP/1.1 caching model, for example:

add_header Age $upstream_cache_age;

Problem:

Current behavior has unintended side effects:

  1. Age header is removed when using: add_header Age $upstream_cache_age
  2. expires directive removes the existing Age header Assumes zero age when setting Expires and Cache-Control

This leads to:

  • Loss of upstream-provided Age information
  • Incorrect cache semantics from a client perspective
  • Deviation from standard HTTP caching behavior

Expected Behavior

  • Preserve upstream Age header unless explicitly overridden
  • Allow $upstream_cache_age to:
    • Override OR
    • Extend existing Age header (configurable behavior)

References Changeset: https://freenginx.org/hg/nginx/rev/e46e1ea89ccd Additional: https://freenginx.org/hg/nginx/rev/8cdab3d89c44

Contributor Guide