Skip to content

Commit e4c39ac

Browse files
authored
Merge pull request rails#54515 from byroot/lazy-route-pattern
Stop eagerly computing `request.route_uri_pattern`
2 parents 28adf46 + 6fd05c9 commit e4c39ac

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

actionpack/lib/action_dispatch/http/request.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,16 @@ def request_method
157157
#
158158
# request.route_uri_pattern # => "/:controller(/:action(/:id))(.:format)"
159159
def route_uri_pattern
160-
get_header("action_dispatch.route_uri_pattern")
160+
unless pattern = get_header("action_dispatch.route_uri_pattern")
161+
route = get_header("action_dispatch.route")
162+
pattern = route.path.spec.to_s
163+
set_header("action_dispatch.route_uri_pattern", pattern)
164+
end
165+
pattern
161166
end
162167

163-
def route_uri_pattern=(pattern) # :nodoc:
164-
set_header("action_dispatch.route_uri_pattern", pattern)
168+
def route=(route) # :nodoc:
169+
set_header("action_dispatch.route", route)
165170
end
166171

167172
def routes # :nodoc:

actionpack/lib/action_dispatch/journey/router.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def serve(req)
4343
}
4444

4545
req.path_parameters = tmp_params
46-
req.route_uri_pattern = route.path.spec.to_s
46+
req.route = route
4747

4848
_, headers, _ = response = route.app.serve(req)
4949

0 commit comments

Comments
 (0)