Class: ExpoTurbo::Rails::VaryHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/expo_turbo/rails/vary_headers.rb

Overview

Stamps the Expo Turbo cache dimensions on the way out, at the Rack layer.

A controller callback cannot reach every response. It is skipped when a host filter halts the chain before the concern's own filter runs, and a response that ActionDispatch::ShowExceptions renders never passes through a controller at all. Both are ordinary responses that a shared cache can store, and both must carry Vary.

The middleware sits immediately outside ActionDispatch::ShowExceptions. That position covers every response the Rails application produces, including its exception pages, and deliberately excludes responses that are produced above it: static files, Rack::Sendfile, host authorization, and the web server itself. Those are not representations of an Expo Turbo resource, so their bytes do not depend on Accept, Turbo-Frame, or the client descriptor or its one-minor legacy fallback.

Constant Summary collapse

DIMENSIONS =
["Accept", "Turbo-Frame", "X-Expo-Turbo-Client", "X-Expo-Turbo-Modules"].freeze
HEADER =
"vary"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ VaryHeaders

Returns a new instance of VaryHeaders.



24
25
26
# File 'lib/expo_turbo/rails/vary_headers.rb', line 24

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



28
29
30
31
# File 'lib/expo_turbo/rails/vary_headers.rb', line 28

def call(env)
  status, headers, body = @app.call(env)
  [status, vary(headers), body]
end