Rack Middleware
Upcoming SlideShare
Loading in...5
×
 

Rack Middleware

on

  • 5,490 views

 

Statistics

Views

Total Views
5,490
Views on SlideShare
5,473
Embed Views
17

Actions

Likes
4
Downloads
56
Comments
0

1 Embed 17

http://www.slideshare.net 17

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Rack Middleware Rack Middleware Presentation Transcript

    • Rack Middleware
    • m/
    • NEED
    • CHOICE
    • Jon Crosby http://joncrosby.me
    • CloudKit http://getcloudkit.com
    • rack-contrib http://github.com/rack/rack-contrib
    • Engine Yard Solo “The platform for on-demand management of your Ruby on Rails application in the cloud.”
    • Free during HackFest
    • Discount for Sign Up
    • CGI
    • app.cgi
    • WARNING
    • Contains Perl
    • old skool perl cgi
    • if ($cgi->param(‘action’) eq ‘all’) { my $sql = “select * from customer”; my $rows = $dbh->selectall_arrayref($sql); if (@$rows) { print “<table border=1>” . “<th>name</th>” . ...
    • if ($cgi->param(‘action’) eq ‘all’) { my $sql = “select * from customer”; my $rows = $dbh->selectall_arrayref($sql); if (@$rows) { print “<table border=1>” . “<th>name</th>” . ...
    • if ($cgi->param(‘action’) eq ‘all’) { my $sql = “select * from customer”; my $rows = $dbh->selectall_arrayref($sql); if (@$rows) { print “<table border=1>” . “<th>name</th>” . ...
    • if ($cgi->param(‘action’) eq ‘all’) { my $sql = “select * from customer”; my $rows = $dbh->selectall_arrayref($sql); if (@$rows) { print “<table border=1>” . “<th>name</th>” . ...
    • if ($cgi->param(‘action’) eq ‘all’) { my $sql = “select * from customer”; my $rows = $dbh->selectall_arrayref($sql); if (@$rows) { print “<table border=1>” . “<th>name</th>” . ...
    • if ($cgi->param(‘action’) eq ‘all’) { my $sql = “select * from customer”; my $rows = $dbh->selectall_arrayref($sql); if (@$rows) { print “<table border=1>” . “<th>name</th>” . ...
    • Monolith
    • :-(
    • Rails
    • Merb Sinatra Mack Ramaze Waves
    • Authentication
    • Single Sign-On
    • Caching
    • Authentication Example: OpenID + OAuth
    • Install Auth Plugin(s)
    • Install Auth Plugin(s) Generate Controllers
    • Install Auth Plugin(s) Generate Controllers Generate Models
    • Install Auth Plugin(s) Generate Controllers Generate Models Generate Migrations
    • Install Auth Plugin(s) Generate Controllers Generate Models Generate Migrations Modify Existing Controllers
    • Install Auth Plugin(s) Generate Controllers Generate Models Generate Migrations Modify Existing Controllers Monkey Patch Rails
    • :-(
    • The Web
    • HTTP
    • Intermediaries HTTP
    • Intermediaries App HTTP
    • Intermediaries App HTTP
    • Rack
    • HTTP
    • Intermediaries HTTP
    • Middleware HTTP
    • Middleware App HTTP
    • Rack is the Web
    • The Web is Rack
    • WSGI
    • SPEC
    • lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Length’ => ‘5’ }, [‘Hello’] ] }
    • lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Length’ => ‘5’ }, [‘Hello’] ] }
    • lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Length’ => ‘5’ }, [‘Hello’] ] }
    • lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Length’ => ‘5’ }, [‘Hello’] ] }
    • lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Length’ => ‘5’ }, [‘Hello’] ] }
    • lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Length’ => ‘5’ }, [‘Hello’] ] }
    • lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Length’ => ‘5’ }, [‘Hello’] ] }
    • run lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Length’ => ‘5’ }, [‘Hello’] ] }
    • config.ru
    • $ rackup config.ru
    • $ curl http://localhost:9292
    • Hello
    • class App def call(env) [200, {...}, [...]] end end
    • SPEC
    • $ rake SPEC
    • Rack::Lint
    • lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Length’ => ‘5’ }, [‘Hello’] ] }
    • env
    • REQUEST_METHOD
    • env[‘REQUEST_METHOD’]
    • GET PUT POST DELETE HEAD OPTIONS TRACE
    • PATH_INFO
    • /items/123
    • HTTP_*
    • HTTP_ACCEPT
    • application/json
    • rack.*
    • rack.input (the input stream)
    • #gets #each #read #rewind
    • yournamespace.*
    • request = Rack::Request.new(env)
    • request.post?
    • request.params[‘id’]
    • request[‘HTTP_IF_MATCH’]
    • m/
    • Middleware App HTTP
    • use MiddlewareA use MiddlewareB use MiddlewareC run app
    • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
    • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
    • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
    • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
    • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
    • rack-contrib http://github.com/rack/rack-contrib
    • Rack::Profiler
    • Rack::MailExceptions
    • Rack::JSONP
    • Rack::CSSHTTPRequest
    • Rack::Cache http://github.com/rtomayko/rack-cache
    • Rack::NotFound
    • 404
    • Middleware App HTTP
    • use MiddlewareA use MiddlewareB use MiddlewareC run app
    • class App def call(env) [200, {...}, [...]] end end
    • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
    • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
    • use MiddlewareA use MiddlewareB use MiddlewareC run app
    • Middleware App HTTP
    • Middleware App HTTP
    • Cooperative Middleware
    • URI Space
    • /*
    • /just-what-it-needs
    • CloudKit
    • Open Web JSON Appliance
    • expose :notes, :todos
    • expose :notes, :todos
    • contain :notes, :todos
    • use Rack::Pool::Session use CloudKit::OAuthFilter use CloudKit::OpenIDFilter use CloudKit::Service, :collections => [:notes, :todos] (run DefaultApp)
    • CloudKit::OAuthFilter /oauth/*
    • CloudKit::OpenIDFilter /login /logout /openid_complete
    • CloudKit::Service /notes/* /todos/*
    • ?
    • Browser OAuth OpenID Service
    • Browser OAuth OpenID Service
    • Browser {...} OAuth OpenID Service
    • Browser OAuth OpenID Service
    • Browser OAuth OpenID Service {...} Login
    • Browser OAuth OpenID Service
    • Browser OAuth OpenID Service
    • Browser OAuth OpenID Service
    • Service or Desktop App OAuth OpenID Service
    • Service or Desktop App OAuth OpenID Service
    • Service or Desktop App {...} OAuth OpenID Service
    • Service or Desktop App OAuth OpenID Service
    • Service or Desktop App OAuth OpenID Service {...} Login
    • Service or Desktop App OAuth OpenID Service
    • Service or Desktop App OAuth OpenID Service
    • Service or Desktop App OAuth OpenID Service
    • Service or Desktop App OAuth OpenID Service
    • Announcing Middleware Presence
    • HTTP Via
    • Via: 1.0 ricky, 1.1 ethel, 1.1 fred
    • Via: 1.0 ricky, 1.1 ethel, 1.1 fred
    • Via: 1.0 ricky, 1.1 ethel, 1.1 fred
    • Via: 1.0 ricky, 1.1 ethel, 1.1 fred
    • env[‘cloudkit.auth’] = 1
    • env[‘cloudkit.via’] << ‘cloudkit.filter.oauth’
    • env[‘cloudkit.via’] << ‘cloudkit.filter.openid’
    • env[‘cloudkit.user’] = ‘http://joncrosby.me’
    • Alternative Stacks
    • Rack::Map
    • map “/” do run Blog::Public end map “/db” do run Blog::DBAdmin end
    • Rack::Map + Sinatra
    • require ‘sinatra/base’ module Blog class Public < Sinatra::Base get ‘/’ do erb :index end end end
    • require ‘sinatra/base’ module Blog class Public < Sinatra::Base get ‘/’ do erb :index end end end
    • require ‘sinatra/base’ module Blog class Public < Sinatra::Base get ‘/’ do erb :index end end end
    • require ‘sinatra’ for “apps” /* URI space
    • require ‘sinatra/base’ MyClass < Sinatra::Base Minimal Sinatra (routing, rendering, etc.)
    • m/
    • use MySinatraApp run SomeOtherApp
    • Rack::Cascade
    • app1 = lambda { ... } app2 = lambda { ... } run Rack::Cascade.new([app1, app2])
    • Sinatra as Middleware in Rails
    • class X < Sinatra::Base get ‘/what’ do ‘what’ end end Rails::Initializer.run do |config| config.use.middleware ‘X’ end
    • CloudKit in Rails
    • Rails::Initializer.run do |config| config.use.middleware ‘CloudKit::Service’, :collections => [:notes, :todos] end
    • Middleware App HTTP
    • Middleware App Rails HTTP
    • Middleware App Rails Merb HTTP
    • Middleware App Rails Merb * HTTP
    • New Unit of Composition
    • m/