Mid-level Track Roadmap

Rails: Rack architecture

This course follows the Rack layer underneath a Rails 8.1 app. It reads the source of ActionDispatch::MiddlewareStack#build and of the MiddlewareStackProxy that records config.middleware calls until late in boot. It explains how Rack::Builder evaluates config.ru and how Puma parses raw HTTP into the env Hash. It shows how Puma writes responses back and why a Rack body only needs to respond to each. It also covers Rack::Response, the Rack::Request::Helpers mixin inside ActionDispatch::Request, and a query string parsing challenge.

What you'll learn

  • ✓How MiddlewareStack#build wraps middlewares with reverse and inject
  • ✓How MiddlewareStackProxy records config.middleware calls and replays them at boot
  • ✓How Rack::Builder evaluates config.ru and what run, use and map do
  • ✓How Puma turns raw HTTP into env and writes the response to the socket
  • ✓Why a Rack body needs each, how streaming works, and what Rack::Response provides
  • ✓How ActionDispatch::Request gets Rack::Request::Helpers through composition
Free preview · Lesson 1 3 min read

The real machine behind config.middleware

The last course's closing challenge asked you to write run_chain(env, middlewares, final_app). You start from final_app, walk the middleware list backward, and wrap each one around the current app. If your solution looked like middlewares.reverse_each { |mw| app = mw.new(app) }, you did more than…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...