Skip to content

Instantly share code, notes, and snippets.

@jamesgary
Created April 30, 2013 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesgary/5492121 to your computer and use it in GitHub Desktop.
Save jamesgary/5492121 to your computer and use it in GitHub Desktop.
From Rails to the web server to client to browser - David Padilla (@dabit) - RailsConf 2013

From Rails to the web server to client to browser

David Padilla @dabit

  • Life of a request
    • Browser creates request
    • Sends it to webserver (Unicorn)
    • Sends it to Rails
    • Sends it to spaghetti code
    • HTML is returned
  • Rack's job is to communicate between webservers and frameworks
  • Only requirements of Rack app:
    • A class that responds to call, then returns [http_code, headers, body]
      • @app.call(env)
    • config.ru
      • require 'app'; run App.new
  • Then call rackup on CLI
  • PRY
    • You can cd into objects
    • ls lists all the methods
  • Experimenting with #call
    • Rails::Application#call is the entry point
    • show-method call shows source code
    • Parameter in call is {"REQUEST_METHOD" => "GET", "PATH_INFO" => '/', "RACK.INPUT" => ""}
    • response[0] # => 200
    • response[1] # => Hash of headers, like 'Content-Length'
    • response[2] # => Array of body
  • Web Request from browser to webserver
    • thin start
      • This calls Thin::Server.start('0.0.0', 3000, app)
      • It can make TcpServers (among other servers, like UnixServer)
      • EventMachine is used to start the server
      • Thin parses request into something Rack can use
      • Zed Shaw wrote the Mongrel parser C extension
    • Unicorn and Puma
      • Doesn't use EventMachine, instead it uses kgio (kinda complicated)
      • Eventually calls @app.call(env)
  • David rolls his own webserver. Cool stuff.
    • Actually not as scary as I thought
  • Don't try this at home, but play around and be curious
  • David's Code on github
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment