9. middlewares call() each other...
and act like chain of response filters...
...so the order you use them matters!
10. init with app
class Reverse
def initialize(app) first, Call the app
@app = app
end
def call(env)
status, headers, body = @app.call(env)
[status, headers, body.map { |b| b.reverse }]
end
end
then, do your stuff
11. use Rack::ContentLength
use RackExamples::Paragraphizer
use RackExamples::Upcase
use
use
RackExamples::Downcase
RackExamples::Reverse
Is output upper or
app = lambda { |env| [
lower case?
200,
{ 'Content-Type' => 'text/html' },
["Dammit, I'm mad!",
"Was it a rat I saw?",
"Madam, I'm Adam"]
] }
run app
11
12. use Rack::ContentLength
use RackExamples::Paragraphizer
use RackExamples::Downcase
use RackExamples::Upcase
use RackExamples::Reverse How about now?
app = lambda { |env| [
200,
{ 'Content-Type' => 'text/html' },
["Dammit, I'm mad!",
"Was it a rat I saw?",
"Madam, I'm Adam"]
] }
run app
12
16. $ rake middleware
(in /Users/sleberkn/Projects/my-niclabs)
use Rack::Lock
use ActionController::Failsafe
use ActionController::Session::CookieStore, #<Proc:0x00000001017acf18@(eval):8>
use ActionController::ParamsParser
use Rack::MethodOverride
use Rack::Head
use ActionController::StringCoercion
use Rack::Deflater
use Sass::Plugin::Rack
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
run ActionController::Dispatcher.new