Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, how do you access the raw request data at the absolute lowest level?

When is the Rails request object available at the earliest time during the request lifecycle? Essentially, when is the request first available as a request object, and in which object? ActionDispatch?

Can you access request parameters from Tester::Application? If so, how? If not, what about using the environment? When is that information set?

like image 395
scottkf Avatar asked Dec 07 '11 21:12

scottkf


2 Answers

The Rack webserver creates the request object and then ActionDispatch inherits from it. So essentially, you'd be able to access the Rack::Request or ActionDispatch::Request objects within the middleware of the app.

Rack::Request

https://github.com/rack/rack/blob/master/lib/rack/request.rb

ActionDispatch::Request

https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/request.rb

like image 115
iwasrobbed Avatar answered Sep 22 '22 23:09

iwasrobbed


A middleware is probably the best way to access this data. I made a simple gem for setting up a raw HTTP request/response log in Rails using the classes mentioned in the accepted answer.

https://github.com/andrhamm/marcopolo

like image 32
andrhamm Avatar answered Sep 24 '22 23:09

andrhamm