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

[rack] use the Rack env instead of the Rack request object #116

Merged
merged 1 commit into from
Apr 20, 2017

Conversation

palazzem
Copy link
Contributor

What it does

Uses directly the env object (we have one env per request) instead of the Rack Request. This is required because in some frameworks (like Rails) the request.path_info could be changed at runtime, especially during exception handling. This makes results not reliable for our http.url tag. For instance:

# suppose we call a Rails endpoint like /error
request = ::Rack::Request.new(env)
assert_equal(request.path_info, '/error')
status, headers, response = @app.call(env)
assert_equal(request.path_info, '/error')  # this fails!

The stored value now is /500.

@palazzem palazzem added the bug Involves a bug label Apr 20, 2017
@palazzem palazzem added this to the 0.7.0 milestone Apr 20, 2017
@palazzem palazzem requested a review from ufoot April 20, 2017 14:06
Copy link
Member

@ufoot ufoot left a comment

Choose a reason for hiding this comment

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

Left a comment on REQUEST_URI vs PATH_INFO but can ship as is, no worry.

# the source of truth in Rack is the PATH_INFO key that holds the
# URL for the current request; some framework may override that
# value, especially during exception handling and because of that
# we prefer using the `REQUEST_URI` if this is available.
Copy link
Member

Choose a reason for hiding this comment

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

I'm OK with this, globally, but on a later release we might dig into it and figure out why a framework would do that, because maybe the PATH_INFO, when it's overridden, is overridden to a value that is technically less related to the "physical" http request but more meaningful in the app context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually PATH_INFO must include the request URL as defined in Rack docs: http://www.rubydoc.info/github/rack/rack/file/SPEC#The_Environment

We may double check on Rails why it's happening. This is just a reasonable default because we know about this exception, but definitely something to take in consideration if it happens also for other frameworks.

Copy link
Member

Choose a reason for hiding this comment

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

👍 good to go, and anyway, this is orthogonal to / independent from the short-term goal we have: have rack support to avoid loosing traces.

@palazzem palazzem merged commit 424be9c into master Apr 20, 2017
@palazzem palazzem deleted the palazzem/rack-env branch April 20, 2017 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants