Skip to content

Instantly share code, notes, and snippets.

@julik
Created June 19, 2014 23:57
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 julik/2d1a1edbef56d2ceb975 to your computer and use it in GitHub Desktop.
Save julik/2d1a1edbef56d2ceb975 to your computer and use it in GitHub Desktop.
Do not double-cook tarballs when serving them via Rack
# Wrapper for Rack::Deflater that will prevent
# the said Deflater from EVER touching .tgz files
class PassthroughDeflater
BYPASS_FILES = /\.(t?)gz$/
# bypass_url_regexp will be matched against PATH_INFO
def initialize(app, bypass_url_regexp = BYPASS_FILES)
@bypass_url_regexp = bypass_url_regexp
@app = app
@deflater = Rack::Deflater.new(@app)
end
def call(env)
if env['PATH_INFO'] =~ @bypass_url_regexp
@app.call(env)
else
@deflater.call(env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment