Skip to content

Commit c747bad

Browse files
authored
Merge branch 'master' into refactor/shared
2 parents 2aacfed + 13a452c commit c747bad

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Examples:
2626

2727
- [React/Vite](https://github.com/BrandonShar/inertia-rails-template)
2828
- [React/Vite + SSR](https://github.com/ElMassimo/inertia-rails-ssr-template)
29+
- [PingCRM with Vue and Vite](https://github.com/ledermann/pingcrm)
2930

3031
## Usage
3132

lib/inertia_rails/renderer.rb

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

2727
def render
28+
@response.set_header('Vary', [@request.headers['Vary'], 'X-Inertia'].compact.join(', '))
2829
if @request.headers['X-Inertia']
29-
@response.set_header('Vary', 'X-Inertia')
3030
@response.set_header('X-Inertia', 'true')
3131
@render_method.call json: page, status: @response.status, content_type: Mime[:json]
3232
else

spec/inertia/rendering_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
context 'first load' do
77
let(:page) { InertiaRails::Renderer.new('TestComponent', controller, request, response, '').send(:page) }
8-
8+
99
context 'with props' do
1010
let(:page) { InertiaRails::Renderer.new('TestComponent', controller, request, response, '', props: {name: 'Brandon', sport: 'hockey'}).send(:page) }
1111
before { get props_path }
@@ -31,6 +31,28 @@
3131
expect(response.status).to eq 200
3232
end
3333

34+
describe 'headers' do
35+
context 'when no other Vary header is present' do
36+
it 'has the proper headers' do
37+
get component_path
38+
39+
expect(response.headers['X-Inertia']).to be_nil
40+
expect(response.headers['Vary']).to eq 'X-Inertia'
41+
expect(response.headers['Content-Type']).to eq 'text/html; charset=utf-8'
42+
end
43+
end
44+
45+
context 'when another Vary header is present' do
46+
it 'has the proper headers' do
47+
get component_path, headers: {'Vary' => 'Accept'}
48+
49+
expect(response.headers['X-Inertia']).to be_nil
50+
expect(response.headers['Vary']).to eq 'Accept, X-Inertia'
51+
expect(response.headers['Content-Type']).to eq 'text/html; charset=utf-8'
52+
end
53+
end
54+
end
55+
3456
context 'via an inertia route' do
3557
before { get inertia_route_path }
3658

0 commit comments

Comments
 (0)