Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output CloudFront-friendly headers for diffs #1098

Merged
merged 1 commit into from
Mar 30, 2023
Merged
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
6 changes: 6 additions & 0 deletions app/controllers/api/v0/diff_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ class Api::V0::DiffController < Api::V0::ApiController
def show
ensure_diffable

# Some front-end caches, like CloudFront, need the headers from *both*
# expires_in and stale? to cache most effectively.
unless Rails.env.development?
cache_time = params[:diff_version] ? 100.years : 1.day
expires_in(cache_time, public: true, stale_while_revalidate: 7.days, stale_if_error: 7.days)
end
if stale?(etag: diff_etag, last_modified: Differ.cache_date, public: true)
render json: {
links: {
Expand Down