Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ac78a9d

Browse files
jorgemanrubiagobijan
andcommittedDec 26, 2024·
Don't choke when controller is not present in the request
Co-authored-by: Bijan Rahnema <bijan@screenisland.com>
1 parent 74c3329 commit ac78a9d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎lib/hotwire/spark/middleware.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def initialize(app)
66
def call(env)
77
status, headers, response = @app.call(env)
88

9-
if html_response?(headers)
9+
if interceptable_request?(headers) && html_response?(headers)
1010
@request = ActionDispatch::Request.new(env)
1111
html = html_from(response)
1212
html = inject_javascript(html)
@@ -19,6 +19,10 @@ def call(env)
1919
end
2020

2121
private
22+
def interceptable_request?(headers)
23+
headers["action_controller.instance"]
24+
end
25+
2226
def html_response?(headers)
2327
headers["Content-Type"]&.include?("text/html")
2428
end

‎test/middleware_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "application_system_test_case"
2+
3+
class MiddlewareTest < ActionDispatch::IntegrationTest
4+
test "error" do
5+
get "/redirected"
6+
end
7+
end

0 commit comments

Comments
 (0)
Please sign in to comment.