Skip to content

Instantly share code, notes, and snippets.

@smerritt
Created May 4, 2009 21:46
Show Gist options
  • Save smerritt/106702 to your computer and use it in GitHub Desktop.
Save smerritt/106702 to your computer and use it in GitHub Desktop.
class RecMiddleware
def initialize(app=nil)
end
def call(env)
env['QUERY_STRING'] ||= "5"
if env['QUERY_STRING'].to_i <= 1
[
200,
{
'Content-Length' => "1",
'Content-Type' => 'text/html',
},
["1"]
]
else
factor = env['QUERY_STRING'].to_i
status, headers, body = RecMiddleware.new.call(env.merge('QUERY_STRING' => (factor - 1).to_s))
new_body = (factor * body[0].to_i).to_s
[status, headers.merge('Content-Length' => new_body.length.to_s), [new_body]]
end
end
end
use RecMiddleware
run lambda{|*args| 'this never gets called' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment