homura-runtime 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/homura/runtime/version.rb +1 -1
  4. data/vendor/rack/auth/abstract/handler.rb +41 -0
  5. data/vendor/rack/auth/abstract/request.rb +51 -0
  6. data/vendor/rack/auth/basic.rb +58 -0
  7. data/vendor/rack/bad_request.rb +8 -0
  8. data/vendor/rack/body_proxy.rb +63 -0
  9. data/vendor/rack/builder.rb +315 -0
  10. data/vendor/rack/cascade.rb +67 -0
  11. data/vendor/rack/common_logger.rb +94 -0
  12. data/vendor/rack/conditional_get.rb +87 -0
  13. data/vendor/rack/config.rb +22 -0
  14. data/vendor/rack/constants.rb +68 -0
  15. data/vendor/rack/content_length.rb +34 -0
  16. data/vendor/rack/content_type.rb +33 -0
  17. data/vendor/rack/deflater.rb +159 -0
  18. data/vendor/rack/directory.rb +210 -0
  19. data/vendor/rack/etag.rb +71 -0
  20. data/vendor/rack/events.rb +172 -0
  21. data/vendor/rack/files.rb +224 -0
  22. data/vendor/rack/head.rb +25 -0
  23. data/vendor/rack/headers.rb +238 -0
  24. data/vendor/rack/lint.rb +1000 -0
  25. data/vendor/rack/lock.rb +29 -0
  26. data/vendor/rack/media_type.rb +42 -0
  27. data/vendor/rack/method_override.rb +56 -0
  28. data/vendor/rack/mime.rb +694 -0
  29. data/vendor/rack/mock.rb +3 -0
  30. data/vendor/rack/mock_request.rb +161 -0
  31. data/vendor/rack/mock_response.rb +147 -0
  32. data/vendor/rack/multipart/generator.rb +99 -0
  33. data/vendor/rack/multipart/parser.rb +586 -0
  34. data/vendor/rack/multipart/uploaded_file.rb +82 -0
  35. data/vendor/rack/multipart.rb +77 -0
  36. data/vendor/rack/null_logger.rb +48 -0
  37. data/vendor/rack/protection/authenticity_token.rb +256 -0
  38. data/vendor/rack/protection/base.rb +140 -0
  39. data/vendor/rack/protection/content_security_policy.rb +80 -0
  40. data/vendor/rack/protection/cookie_tossing.rb +77 -0
  41. data/vendor/rack/protection/escaped_params.rb +93 -0
  42. data/vendor/rack/protection/form_token.rb +25 -0
  43. data/vendor/rack/protection/frame_options.rb +39 -0
  44. data/vendor/rack/protection/http_origin.rb +43 -0
  45. data/vendor/rack/protection/ip_spoofing.rb +27 -0
  46. data/vendor/rack/protection/json_csrf.rb +60 -0
  47. data/vendor/rack/protection/path_traversal.rb +45 -0
  48. data/vendor/rack/protection/referrer_policy.rb +27 -0
  49. data/vendor/rack/protection/remote_referrer.rb +22 -0
  50. data/vendor/rack/protection/remote_token.rb +24 -0
  51. data/vendor/rack/protection/session_hijacking.rb +37 -0
  52. data/vendor/rack/protection/strict_transport.rb +41 -0
  53. data/vendor/rack/protection/version.rb +7 -0
  54. data/vendor/rack/protection/xss_header.rb +27 -0
  55. data/vendor/rack/protection.rb +58 -0
  56. data/vendor/rack/query_parser.rb +261 -0
  57. data/vendor/rack/recursive.rb +66 -0
  58. data/vendor/rack/reloader.rb +112 -0
  59. data/vendor/rack/request.rb +818 -0
  60. data/vendor/rack/response.rb +403 -0
  61. data/vendor/rack/rewindable_input.rb +116 -0
  62. data/vendor/rack/runtime.rb +35 -0
  63. data/vendor/rack/sendfile.rb +197 -0
  64. data/vendor/rack/session/abstract/id.rb +533 -0
  65. data/vendor/rack/session/constants.rb +13 -0
  66. data/vendor/rack/session/cookie.rb +292 -0
  67. data/vendor/rack/session/encryptor.rb +415 -0
  68. data/vendor/rack/session/pool.rb +76 -0
  69. data/vendor/rack/session/version.rb +10 -0
  70. data/vendor/rack/session.rb +12 -0
  71. data/vendor/rack/show_exceptions.rb +433 -0
  72. data/vendor/rack/show_status.rb +121 -0
  73. data/vendor/rack/static.rb +188 -0
  74. data/vendor/rack/tempfile_reaper.rb +44 -0
  75. data/vendor/rack/urlmap.rb +99 -0
  76. data/vendor/rack/utils.rb +631 -0
  77. data/vendor/rack/version.rb +17 -0
  78. data/vendor/rack.rb +66 -0
  79. metadata +76 -1
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+ require_relative 'utils'
5
+ require_relative 'body_proxy'
6
+ require_relative 'request'
7
+
8
+ module Rack
9
+ # Rack::CommonLogger forwards every request to the given +app+, and
10
+ # logs a line in the
11
+ # {Apache common log format}[http://httpd.apache.org/docs/1.3/logs.html#common]
12
+ # to the configured logger.
13
+ class CommonLogger
14
+ # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
15
+ #
16
+ # lilith.local - - [07/Aug/2006 23:58:02 -0400] "GET / HTTP/1.1" 500 -
17
+ #
18
+ # %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
19
+ #
20
+ # The actual format is slightly different than the above due to the
21
+ # separation of SCRIPT_NAME and PATH_INFO, and because the elapsed
22
+ # time in seconds is included at the end.
23
+ FORMAT = %{%s - %s [%s] "%s %s%s%s %s" %d %s %0.4f }
24
+
25
+ # +logger+ can be any object that supports the +write+ or +<<+ methods,
26
+ # which includes the standard library Logger. These methods are called
27
+ # with a single string argument, the log message.
28
+ # If +logger+ is nil, CommonLogger will fall back <tt>env['rack.errors']</tt>.
29
+ def initialize(app, logger = nil)
30
+ @app = app
31
+ @logger = logger
32
+ end
33
+
34
+ # Log all requests in common_log format after a response has been
35
+ # returned. Note that if the app raises an exception, the request
36
+ # will not be logged, so if exception handling middleware are used,
37
+ # they should be loaded after this middleware. Additionally, because
38
+ # the logging happens after the request body has been fully sent, any
39
+ # exceptions raised during the sending of the response body will
40
+ # cause the request not to be logged.
41
+ def call(env)
42
+ began_at = Utils.clock_time
43
+ status, headers, body = response = @app.call(env)
44
+
45
+ response[2] = BodyProxy.new(body) { log(env, status, headers, began_at) }
46
+ response
47
+ end
48
+
49
+ private
50
+
51
+ # Log the request to the configured logger.
52
+ def log(env, status, response_headers, began_at)
53
+ request = Rack::Request.new(env)
54
+ length = extract_content_length(response_headers)
55
+
56
+ msg = sprintf(FORMAT,
57
+ request.ip || "-",
58
+ request.get_header("REMOTE_USER") || "-",
59
+ Time.now.strftime("%d/%b/%Y:%H:%M:%S %z"),
60
+ request.request_method,
61
+ request.script_name,
62
+ request.path_info,
63
+ request.query_string.empty? ? "" : "?#{request.query_string}",
64
+ request.get_header(SERVER_PROTOCOL),
65
+ status.to_s[0..3],
66
+ length,
67
+ Utils.clock_time - began_at)
68
+
69
+ # homura: Opal Strings are immutable, so use non-mutating gsub +
70
+ # chomp + concat instead of `gsub!` / `String#[]=`. Behaviour
71
+ # identical on MRI; required to keep CommonLogger usable when
72
+ # Sinatra default-middleware is active under the Workers + Opal
73
+ # stack.
74
+ msg = msg.gsub(/[^[:print:]]/) { |c| sprintf("\\x%x", c.ord) }
75
+ msg = msg.chomp + "\n"
76
+
77
+ logger = @logger || request.get_header(RACK_ERRORS)
78
+ # Standard library logger doesn't support write but it supports << which actually
79
+ # calls to write on the log device without formatting
80
+ if logger.respond_to?(:write)
81
+ logger.write(msg)
82
+ else
83
+ logger << msg
84
+ end
85
+ end
86
+
87
+ # Attempt to determine the content length for the response to
88
+ # include it in the logged data.
89
+ def extract_content_length(headers)
90
+ value = headers[CONTENT_LENGTH]
91
+ !value || value.to_s == '0' ? '-' : value
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+ require_relative 'utils'
5
+ require_relative 'body_proxy'
6
+
7
+ module Rack
8
+
9
+ # Middleware that enables conditional GET using if-none-match and
10
+ # if-modified-since. The application should set either or both of the
11
+ # last-modified or etag response headers according to RFC 2616. When
12
+ # either of the conditions is met, the response body is set to be zero
13
+ # length and the response status is set to 304 Not Modified.
14
+ #
15
+ # Applications that defer response body generation until the body's each
16
+ # message is received will avoid response body generation completely when
17
+ # a conditional GET matches.
18
+ #
19
+ # Adapted from Michael Klishin's Merb implementation:
20
+ # https://github.com/wycats/merb/blob/master/merb-core/lib/merb-core/rack/middleware/conditional_get.rb
21
+ class ConditionalGet
22
+ def initialize(app)
23
+ @app = app
24
+ end
25
+
26
+ # Return empty 304 response if the response has not been
27
+ # modified since the last request.
28
+ def call(env)
29
+ case env[REQUEST_METHOD]
30
+ when "GET", "HEAD"
31
+ status, headers, body = response = @app.call(env)
32
+
33
+ if status == 200 && fresh?(env, headers)
34
+ response[0] = 304
35
+ headers.delete(CONTENT_TYPE)
36
+ headers.delete(CONTENT_LENGTH)
37
+
38
+ # We are done with the body:
39
+ body.close if body.respond_to?(:close)
40
+ response[2] = []
41
+ end
42
+ response
43
+ else
44
+ @app.call(env)
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ # Return whether the response has not been modified since the
51
+ # last request.
52
+ def fresh?(env, headers)
53
+ # if-none-match has priority over if-modified-since per RFC 7232
54
+ if none_match = env['HTTP_IF_NONE_MATCH']
55
+ etag_matches?(none_match, headers)
56
+ elsif (modified_since = env['HTTP_IF_MODIFIED_SINCE']) && (modified_since = to_rfc2822(modified_since))
57
+ modified_since?(modified_since, headers)
58
+ end
59
+ end
60
+
61
+ # Whether the etag response header matches the if-none-match request header.
62
+ # If so, the request has not been modified.
63
+ def etag_matches?(none_match, headers)
64
+ headers[ETAG] == none_match
65
+ end
66
+
67
+ # Whether the last-modified response header matches the if-modified-since
68
+ # request header. If so, the request has not been modified.
69
+ def modified_since?(modified_since, headers)
70
+ last_modified = to_rfc2822(headers['last-modified']) and
71
+ modified_since >= last_modified
72
+ end
73
+
74
+ # Return a Time object for the given string (which should be in RFC2822
75
+ # format), or nil if the string cannot be parsed.
76
+ def to_rfc2822(since)
77
+ # shortest possible valid date is the obsolete: 1 Nov 97 09:55 A
78
+ # anything shorter is invalid, this avoids exceptions for common cases
79
+ # most common being the empty string
80
+ if since && since.length >= 16
81
+ # NOTE: there is no trivial way to write this in a non exception way
82
+ # _rfc2822 returns a hash but is not that usable
83
+ Time.rfc2822(since) rescue nil
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ # Rack::Config modifies the environment using the block given during
5
+ # initialization.
6
+ #
7
+ # Example:
8
+ # use Rack::Config do |env|
9
+ # env['my-key'] = 'some-value'
10
+ # end
11
+ class Config
12
+ def initialize(app, &block)
13
+ @app = app
14
+ @block = block
15
+ end
16
+
17
+ def call(env)
18
+ @block.call(env)
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ # Request env keys
5
+ HTTP_HOST = 'HTTP_HOST'
6
+ HTTP_PORT = 'HTTP_PORT'
7
+ HTTPS = 'HTTPS'
8
+ PATH_INFO = 'PATH_INFO'
9
+ REQUEST_METHOD = 'REQUEST_METHOD'
10
+ REQUEST_PATH = 'REQUEST_PATH'
11
+ SCRIPT_NAME = 'SCRIPT_NAME'
12
+ QUERY_STRING = 'QUERY_STRING'
13
+ SERVER_PROTOCOL = 'SERVER_PROTOCOL'
14
+ SERVER_NAME = 'SERVER_NAME'
15
+ SERVER_PORT = 'SERVER_PORT'
16
+ HTTP_COOKIE = 'HTTP_COOKIE'
17
+
18
+ # Response Header Keys
19
+ CACHE_CONTROL = 'cache-control'
20
+ CONTENT_LENGTH = 'content-length'
21
+ CONTENT_TYPE = 'content-type'
22
+ ETAG = 'etag'
23
+ EXPIRES = 'expires'
24
+ SET_COOKIE = 'set-cookie'
25
+ TRANSFER_ENCODING = 'transfer-encoding'
26
+
27
+ # HTTP method verbs
28
+ GET = 'GET'
29
+ POST = 'POST'
30
+ PUT = 'PUT'
31
+ PATCH = 'PATCH'
32
+ DELETE = 'DELETE'
33
+ HEAD = 'HEAD'
34
+ OPTIONS = 'OPTIONS'
35
+ CONNECT = 'CONNECT'
36
+ LINK = 'LINK'
37
+ UNLINK = 'UNLINK'
38
+ TRACE = 'TRACE'
39
+
40
+ # Rack environment variables
41
+ RACK_VERSION = 'rack.version'
42
+ RACK_TEMPFILES = 'rack.tempfiles'
43
+ RACK_EARLY_HINTS = 'rack.early_hints'
44
+ RACK_ERRORS = 'rack.errors'
45
+ RACK_LOGGER = 'rack.logger'
46
+ RACK_INPUT = 'rack.input'
47
+ RACK_SESSION = 'rack.session'
48
+ RACK_SESSION_OPTIONS = 'rack.session.options'
49
+ RACK_SHOWSTATUS_DETAIL = 'rack.showstatus.detail'
50
+ RACK_URL_SCHEME = 'rack.url_scheme'
51
+ RACK_HIJACK = 'rack.hijack'
52
+ RACK_IS_HIJACK = 'rack.hijack?'
53
+ RACK_RECURSIVE_INCLUDE = 'rack.recursive.include'
54
+ RACK_MULTIPART_BUFFER_SIZE = 'rack.multipart.buffer_size'
55
+ RACK_MULTIPART_TEMPFILE_FACTORY = 'rack.multipart.tempfile_factory'
56
+ RACK_RESPONSE_FINISHED = 'rack.response_finished'
57
+ RACK_PROTOCOL = 'rack.protocol'
58
+ RACK_REQUEST_FORM_INPUT = 'rack.request.form_input'
59
+ RACK_REQUEST_FORM_HASH = 'rack.request.form_hash'
60
+ RACK_REQUEST_FORM_PAIRS = 'rack.request.form_pairs'
61
+ RACK_REQUEST_FORM_VARS = 'rack.request.form_vars'
62
+ RACK_REQUEST_FORM_ERROR = 'rack.request.form_error'
63
+ RACK_REQUEST_COOKIE_HASH = 'rack.request.cookie_hash'
64
+ RACK_REQUEST_COOKIE_STRING = 'rack.request.cookie_string'
65
+ RACK_REQUEST_QUERY_HASH = 'rack.request.query_hash'
66
+ RACK_REQUEST_QUERY_STRING = 'rack.request.query_string'
67
+ RACK_METHODOVERRIDE_ORIGINAL_METHOD = 'rack.methodoverride.original_method'
68
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+ require_relative 'utils'
5
+
6
+ module Rack
7
+
8
+ # Sets the content-length header on responses that do not specify
9
+ # a content-length or transfer-encoding header. Note that this
10
+ # does not fix responses that have an invalid content-length
11
+ # header specified.
12
+ class ContentLength
13
+ include Rack::Utils
14
+
15
+ def initialize(app)
16
+ @app = app
17
+ end
18
+
19
+ def call(env)
20
+ status, headers, body = response = @app.call(env)
21
+
22
+ if !STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i) &&
23
+ !headers[CONTENT_LENGTH] &&
24
+ !headers[TRANSFER_ENCODING] &&
25
+ body.respond_to?(:to_ary)
26
+
27
+ response[2] = body = body.to_ary
28
+ headers[CONTENT_LENGTH] = body.sum(&:bytesize).to_s
29
+ end
30
+
31
+ response
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'constants'
4
+ require_relative 'utils'
5
+
6
+ module Rack
7
+
8
+ # Sets the content-type header on responses which don't have one.
9
+ #
10
+ # Builder Usage:
11
+ # use Rack::ContentType, "text/plain"
12
+ #
13
+ # When no content type argument is provided, "text/html" is the
14
+ # default.
15
+ class ContentType
16
+ include Rack::Utils
17
+
18
+ def initialize(app, content_type = "text/html")
19
+ @app = app
20
+ @content_type = content_type
21
+ end
22
+
23
+ def call(env)
24
+ status, headers, _ = response = @app.call(env)
25
+
26
+ unless STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i)
27
+ headers[CONTENT_TYPE] ||= @content_type
28
+ end
29
+
30
+ response
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zlib"
4
+ require "time" # for Time.httpdate
5
+
6
+ require_relative 'constants'
7
+ require_relative 'utils'
8
+ require_relative 'request'
9
+ require_relative 'body_proxy'
10
+
11
+ module Rack
12
+ # This middleware enables content encoding of http responses,
13
+ # usually for purposes of compression.
14
+ #
15
+ # Currently supported encodings:
16
+ #
17
+ # * gzip
18
+ # * identity (no transformation)
19
+ #
20
+ # This middleware automatically detects when encoding is supported
21
+ # and allowed. For example no encoding is made when a cache
22
+ # directive of 'no-transform' is present, when the response status
23
+ # code is one that doesn't allow an entity body, or when the body
24
+ # is empty.
25
+ #
26
+ # Note that despite the name, Deflater does not support the +deflate+
27
+ # encoding.
28
+ class Deflater
29
+
30
+ GZIP_MTIME = RUBY_VERSION >= "2.7" ? 0 : 1
31
+
32
+ # Creates Rack::Deflater middleware. Options:
33
+ #
34
+ # :if :: a lambda enabling / disabling deflation based on returned boolean value
35
+ # (e.g <tt>use Rack::Deflater, :if => lambda { |*, body| sum=0; body.each { |i| sum += i.length }; sum > 512 }</tt>).
36
+ # However, be aware that calling `body.each` inside the block will break cases where `body.each` is not idempotent,
37
+ # such as when it is an +IO+ instance.
38
+ # :include :: a list of content types that should be compressed. By default, all content types are compressed.
39
+ # :sync :: determines if the stream is going to be flushed after every chunk. Flushing after every chunk reduces
40
+ # latency for time-sensitive streaming applications, but hurts compression and throughput.
41
+ # Defaults to +true+.
42
+ def initialize(app, options = {})
43
+ @app = app
44
+ @condition = options[:if]
45
+ @compressible_types = options[:include]
46
+ @sync = options.fetch(:sync, true)
47
+ end
48
+
49
+ def call(env)
50
+ status, headers, body = response = @app.call(env)
51
+
52
+ unless should_deflate?(env, status, headers, body)
53
+ return response
54
+ end
55
+
56
+ request = Request.new(env)
57
+
58
+ encoding = Utils.select_best_encoding(%w(gzip identity),
59
+ request.accept_encoding)
60
+
61
+ # Set the Vary HTTP header.
62
+ vary = headers["vary"].to_s.split(",").map(&:strip)
63
+ unless vary.include?("*") || vary.any?{|v| v.downcase == 'accept-encoding'}
64
+ headers["vary"] = vary.push("Accept-Encoding").join(",")
65
+ end
66
+
67
+ case encoding
68
+ when "gzip"
69
+ headers['content-encoding'] = "gzip"
70
+ headers.delete(CONTENT_LENGTH)
71
+ response[2] = GzipStream.new(body, GZIP_MTIME, @sync)
72
+ response
73
+ when "identity"
74
+ response
75
+ else # when nil
76
+ # Only possible encoding values here are 'gzip', 'identity', and nil
77
+ message = "An acceptable encoding for the requested resource #{request.fullpath} could not be found."
78
+ bp = Rack::BodyProxy.new([message]) { body.close if body.respond_to?(:close) }
79
+ [406, { CONTENT_TYPE => "text/plain", CONTENT_LENGTH => message.length.to_s }, bp]
80
+ end
81
+ end
82
+
83
+ # Body class used for gzip encoded responses.
84
+ class GzipStream
85
+
86
+ BUFFER_LENGTH = 128 * 1_024
87
+
88
+ # Initialize the gzip stream. Arguments:
89
+ # body :: Response body to compress with gzip
90
+ # mtime :: The modification time of the body, used to set the
91
+ # modification time in the gzip header.
92
+ # sync :: Whether to flush each gzip chunk as soon as it is ready.
93
+ def initialize(body, mtime, sync)
94
+ @body = body
95
+ @mtime = mtime
96
+ @sync = sync
97
+ end
98
+
99
+ # Yield gzip compressed strings to the given block.
100
+ def each(&block)
101
+ @writer = block
102
+ gzip = ::Zlib::GzipWriter.new(self)
103
+ gzip.mtime = @mtime if @mtime
104
+ # @body.each is equivalent to @body.gets (slow)
105
+ if @body.is_a? ::File # XXX: Should probably be ::IO
106
+ while part = @body.read(BUFFER_LENGTH)
107
+ gzip.write(part)
108
+ gzip.flush if @sync
109
+ end
110
+ else
111
+ @body.each { |part|
112
+ # Skip empty strings, as they would result in no output,
113
+ # and flushing empty parts would raise Zlib::BufError.
114
+ next if part.empty?
115
+ gzip.write(part)
116
+ gzip.flush if @sync
117
+ }
118
+ end
119
+ ensure
120
+ gzip.finish
121
+ end
122
+
123
+ # Call the block passed to #each with the gzipped data.
124
+ def write(data)
125
+ @writer.call(data)
126
+ end
127
+
128
+ # Close the original body if possible.
129
+ def close
130
+ @body.close if @body.respond_to?(:close)
131
+ end
132
+ end
133
+
134
+ private
135
+
136
+ # Whether the body should be compressed.
137
+ def should_deflate?(env, status, headers, body)
138
+ # Skip compressing empty entity body responses and responses with
139
+ # no-transform set.
140
+ if Utils::STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i) ||
141
+ /\bno-transform\b/.match?(headers[CACHE_CONTROL].to_s) ||
142
+ headers['content-encoding']&.!~(/\bidentity\b/)
143
+ return false
144
+ end
145
+
146
+ # Skip if @compressible_types are given and does not include request's content type
147
+ return false if @compressible_types && !(headers.has_key?(CONTENT_TYPE) && @compressible_types.include?(headers[CONTENT_TYPE][/[^;]*/]))
148
+
149
+ # Skip if @condition lambda is given and evaluates to false
150
+ return false if @condition && !@condition.call(env, status, headers, body)
151
+
152
+ # No point in compressing empty body, also handles usage with
153
+ # Rack::Sendfile.
154
+ return false if headers[CONTENT_LENGTH] == '0'
155
+
156
+ true
157
+ end
158
+ end
159
+ end