Skip to content

Instantly share code, notes, and snippets.

@brianstorti
Last active August 29, 2015 14:08
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 brianstorti/74e81c68cab106fc9693 to your computer and use it in GitHub Desktop.
Save brianstorti/74e81c68cab106fc9693 to your computer and use it in GitHub Desktop.
Example rack middlewares
class Canadianize
def initialize(app, arg = "")
@app = app
@arg = arg
end
def call(env)
status, headers, content = @app.call(env)
content[0] += @arg + ", eh?"
[ status, headers, content ]
end
end
class Gauchanize
def initialize(app, arg = "")
@app = app
@arg = arg
end
def call(env)
status, headers, content = @app.call(env)
content[0] = "Bah, " + content[0] + @arg
[ status, headers, content ]
end
end
use Canadianize, ", simple"
use Gauchanize
run proc {
[200,
{'Content-Type' => 'text/html'},
["Hello, world"]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment