Created
June 19, 2014 23:57
-
-
Save julik/2d1a1edbef56d2ceb975 to your computer and use it in GitHub Desktop.
Do not double-cook tarballs when serving them via Rack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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