Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions contract/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,14 @@ func TestSpec_MutationCanary(t *testing.T) {
const ranks200Block = ` "200":
description: Rank reference list.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down
145 changes: 145 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ paths:
"200":
description: The full milpac profile.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -115,6 +123,14 @@ paths:
"200":
description: The full milpac profile.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -150,6 +166,14 @@ paths:
"200":
description: The full milpac profile.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -185,6 +209,14 @@ paths:
"200":
description: The full milpac profile.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -216,6 +248,14 @@ paths:
"200":
description: Profiles keyed by milpac relation id.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -251,6 +291,14 @@ paths:
"200":
description: Lite profiles keyed by milpac relation id.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -284,6 +332,14 @@ paths:
"200":
description: S1 uniforms profiles keyed by milpac relation id.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -336,6 +392,14 @@ paths:
Matching lite profiles keyed by milpac relation id; {} when
nothing matches (200, never 404).
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -365,6 +429,14 @@ paths:
"200":
description: Rank reference list.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -394,6 +466,14 @@ paths:
"200":
description: Position group reference tree.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -421,6 +501,14 @@ paths:
"200":
description: AWOL list.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -453,6 +541,14 @@ paths:
"200":
description: Forum group directory.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: data may be up to 10 minutes stale.
Expand Down Expand Up @@ -576,6 +672,14 @@ paths:
"200":
description: One page of tickets.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: always served live. Responses are
Expand Down Expand Up @@ -617,6 +721,14 @@ paths:
"200":
description: The ticket with its first messages.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: always served live. Responses are
Expand Down Expand Up @@ -655,6 +767,14 @@ paths:
"200":
description: The ticket with its first messages.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: always served live. Responses are
Expand Down Expand Up @@ -715,6 +835,14 @@ paths:
"200":
description: One page of the message thread.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: always served live. Responses are
Expand Down Expand Up @@ -745,6 +873,14 @@ paths:
"200":
description: Category reference tree.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
Cache-Control:
description: >-
Freshness signal: always served live. Responses are
Expand Down Expand Up @@ -826,6 +962,15 @@ components:
JSON error body. `code` is a numeric status code (3 InvalidArgument →
400, 5 NotFound → 404, 7 PermissionDenied → 403, 13 Internal → 500).
`message` is a human-readable description of the failure.
headers:
Vary:
description: >-
Cache-keying hint: the server selects the body encoding from
Accept-Encoding, so a shared cache must store the gzip and
identity variants under separate keys.
schema:
type: string
const: Accept-Encoding
content:
application/json:
schema:
Expand Down
11 changes: 11 additions & 0 deletions rest/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ import (
// closed.
func GzipMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// The response body is selected by proactive content negotiation on
// Accept-Encoding, so declare that to any shared cache: it must key each
// encoding variant separately rather than serve one body for both.
// Applied unconditionally, before the branch, so every response that
// reaches this layer inherits it (the outer auth 401 short-circuits
// before it) — the gzip branch and the identity pass-through alike, and
// every status, including the bodyless 204/304 finals (Vary is a
// cache-keying hint, so it is correct to keep there, unlike the
// Content-Encoding stripped off them below). Add, not Set, so a Vary
// value already set by an outer layer survives — Set would drop it.
w.Header().Add("Vary", "Accept-Encoding")
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
w.Header().Set("Content-Encoding", "gzip")
gz := gzip.NewWriter(w)
Expand Down
Loading