Created
June 16, 2011 04:35
-
-
Save moro/1028677 to your computer and use it in GitHub Desktop.
samp.ru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack' | |
class App | |
def call(env) | |
to = Rack::Request.new(env).params["to"] || "World" | |
body = Rack::Utils.escape_html(to) | |
[200, {"Content-Type" => "text/html"}, [body]] | |
end | |
end | |
class HelloMiddleware | |
def initialize(app, opts) | |
@app = app | |
@msg = Rack::Utils.escape_html(opts[:message] || "Hello ") | |
end | |
def call(env) | |
status, header, body = @app.call(env) | |
[status, header, ["#{@msg} "] + body] | |
end | |
end | |
use Rack::Lint | |
use HelloMiddleware, :message => "Good morning " | |
run App.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment