Skip to content

Instantly share code, notes, and snippets.

@timriley
Created December 8, 2011 07:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timriley/1446347 to your computer and use it in GitHub Desktop.
Save timriley/1446347 to your computer and use it in GitHub Desktop.
How to override Rack middleware so it doesn't run in certain circumstances
module Rack
class DeflaterWithExclusions < Deflater
def initialize(app, options = {})
@app = app
@exclude = options[:exclude]
end
def call(env)
if @exclude && @exclude.call(env)
@app.call(env)
else
super(env)
end
end
end
end
use Rack::DeflaterWithExclusions, :exclude => proc { |env| env['PATH_INFO'] == '/some/url' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment