Skip to content

Instantly share code, notes, and snippets.

@ajokela
Created June 5, 2012 21:06
Show Gist options
  • Save ajokela/2877935 to your computer and use it in GitHub Desktop.
Save ajokela/2877935 to your computer and use it in GitHub Desktop.
Rack::Callbacks
class TimeZone
def initialize(default)
@default = default
end
def call(env)
env['rack.timezone'] = find_timezone(env) || @default
end
end
class CompressBody
def call(response)
status, headers, body = response
compressed_body = zip_body(body)
[status, headers, compressed_body]
end
end
app = Rack::Callbacks.new do
before TimeZone, "default"
run YourPrimaryRackApp.new
after CompressBody
end
run app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment