Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTP::Request#route_uri_pattern that returns URI pattern of matched route. #47129

Merged
merged 2 commits into from Jan 25, 2023

Conversation

joelhawksley
Copy link
Contributor

Motivation / Background

In the GitHub RoR monolith, we output the route URI pattern in an HTML meta tag in our application layout for analysis purposes. However, our current implementation is quite manual.

Detail

This change adds an attribute to requests with the URI pattern of the matched route.

Additional information

Co-authored-by: Kate Higa khiga8@github.com

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot bot added the actionpack label Jan 24, 2023
@@ -57,6 +57,8 @@ def self.empty
new({})
end

attr_accessor :route_uri_pattern
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should implement this using the rack env so middleware can also have access to the information. See routes= for example.

@joelhawksley
Copy link
Contributor Author

@rafaelfranca thanks for the suggestions in your review. I've updated the PR accordingly ❤️

@@ -153,6 +153,14 @@ def routes=(routes) # :nodoc:
set_header("action_dispatch.routes", routes)
end

def route_uri_pattern # :nodoc:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def route_uri_pattern # :nodoc:
def route_uri_pattern

We want this method to be public API so we need to document it.

In the GitHub RoR monolith, we output the route URI pattern
in an HTML meta tag in our application layout for analysis
purposes. However, our current implementation is quite manual.

This change adds an attribute to requests with the URI pattern
of the matched route.

Co-authored-by: Kate Higa <khiga8@github.com>
@joelhawksley joelhawksley changed the title Tag HTTP::Request with route URI pattern Add HTTP::Request#route_uri_pattern that returns URI pattern of matched route. Jan 25, 2023
@rafaelfranca rafaelfranca merged commit 2fc46f9 into rails:main Jan 25, 2023
@joelhawksley joelhawksley deleted the current-route branch January 25, 2023 21:45
get_header("action_dispatch.route_uri_pattern")
end

def route_uri_pattern=(pattern) # :nodoc:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelhawksley I've opened #47306 but I was thinking we might want to add a test for this if possible? WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants