Skip to content

Instantly share code, notes, and snippets.

@moro
Created June 16, 2011 04:35
Show Gist options
  • Save moro/1028677 to your computer and use it in GitHub Desktop.
Save moro/1028677 to your computer and use it in GitHub Desktop.
samp.ru
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