Skip to content

Commit

Permalink
Updated Deflater configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubpawlowicz committed Nov 14, 2012
1 parent 9385496 commit 4e883df
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/rack/deflater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ module Rack
class Deflater
def initialize(app, options = {})
@app = app
@options = options

@min_content_length = options[:min_content_length]
@skip_if = options[:skip_if]
@exclude = options[:exclude]
end

def call(env)
Expand Down Expand Up @@ -110,21 +113,21 @@ def should_deflate?(env, status, headers, body)
end

# Skip if response body is too short
if @options[:min_content_length] &&
@options[:min_content_length] > headers['Content-Length'].to_i
if @min_content_length &&
@min_content_length > headers['Content-Length'].to_i
return false
end

# Skip if :exclude is provided and evaluates to true
if @options[:exclude] &&
@options[:exclude].kind_of?(Regexp) &&
@options[:exclude].match(env['PATH_INFO'])
if @exclude &&
@exclude.kind_of?(Regexp) &&
@exclude.match(env['PATH_INFO'])
return false
end

# Skip if :skip_if lambda is provided and evaluates to true
if @options[:skip_if] &&
@options[:skip_if].call(env, status, headers, body)
if @skip_if &&
@skip_if.call(env, status, headers, body)
return false
end

Expand Down

0 comments on commit 4e883df

Please sign in to comment.