Skip to content

Commit 4472cea

Browse files
committed
add: add "Vary" header to responses
1 parent d10c779 commit 4472cea

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. From versio
1010
- Add a `HINT` when the LISTEN channel stops working due to a PostgreSQL bug by @laurenceisla in #4581
1111
- Add string slicing operator for `jwt-role-claim-key` by @taimoorzaeem in #4599
1212
- Log host, port and pg version of listener database connection by @mkleczek in #4617 #4618
13+
- Add `Vary` header to responses by @develop7 in #4609
1314

1415
### Fixed
1516

src/PostgREST/App.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ postgrestResponse appState conf@AppConfig{..} maybeSchemaCache authResult@AuthRe
178178

179179
where
180180
toWaiResponse :: ServerTiming -> Response.PgrstResponse -> Wai.Response
181-
toWaiResponse timing (Response.PgrstResponse st hdrs bod) = Wai.responseLBS st (hdrs ++ ([serverTimingHeader timing | configServerTimingEnabled])) bod
181+
toWaiResponse timing (Response.PgrstResponse st hdrs bod) =
182+
Wai.responseLBS st (hdrs ++ serverTimingHeaders timing ++ [varyHeader]) bod
183+
184+
varyHeader :: HTTP.Header
185+
varyHeader = ("Vary", "Accept-Encoding, Accept, Prefer, Range")
186+
187+
serverTimingHeaders :: ServerTiming -> [HTTP.Header]
188+
serverTimingHeaders timing = [serverTimingHeader timing | configServerTimingEnabled]
182189

183190
withTiming :: Handler IO a -> Handler IO (Maybe Double, a)
184191
withTiming f = if configServerTimingEnabled

0 commit comments

Comments
 (0)