Skip to content

Commit 9dca481

Browse files
committed
Set Vary header to X-Inertia on HTML responses
1 parent 6e0fc5a commit 9dca481

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/inertia_rails/renderer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def initialize(component, controller, request, response, render_method, props: n
1616
end
1717

1818
def render
19+
@response.set_header('Vary', 'X-Inertia')
1920
if @request.headers['X-Inertia']
20-
@response.set_header('Vary', 'X-Inertia')
2121
@response.set_header('X-Inertia', 'true')
2222
@render_method.call json: page, status: @response.status, content_type: Mime[:json]
2323
else

spec/inertia/rendering_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
expect(response.status).to eq 200
3232
end
3333

34+
it 'has the proper headers' do
35+
get component_path
36+
37+
expect(response.headers['X-Inertia']).to be_nil
38+
expect(response.headers['Vary']).to eq 'X-Inertia'
39+
expect(response.headers['Content-Type']).to eq 'text/html; charset=utf-8'
40+
end
41+
3442
context 'via an inertia route' do
3543
before { get inertia_route_path }
3644

0 commit comments

Comments
 (0)