rack 2.1.0 → 2.2.2

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.

Potentially problematic release.


This version of rack might be problematic. Click here for more details.

Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +126 -6
  3. data/CONTRIBUTING.md +136 -0
  4. data/README.rdoc +83 -39
  5. data/Rakefile +14 -7
  6. data/{SPEC → SPEC.rdoc} +26 -1
  7. data/lib/rack.rb +7 -16
  8. data/lib/rack/auth/abstract/request.rb +0 -2
  9. data/lib/rack/auth/basic.rb +3 -3
  10. data/lib/rack/auth/digest/md5.rb +4 -4
  11. data/lib/rack/auth/digest/request.rb +3 -3
  12. data/lib/rack/body_proxy.rb +13 -9
  13. data/lib/rack/builder.rb +78 -8
  14. data/lib/rack/cascade.rb +23 -8
  15. data/lib/rack/chunked.rb +48 -23
  16. data/lib/rack/common_logger.rb +25 -18
  17. data/lib/rack/conditional_get.rb +18 -16
  18. data/lib/rack/content_length.rb +6 -7
  19. data/lib/rack/content_type.rb +3 -4
  20. data/lib/rack/deflater.rb +49 -35
  21. data/lib/rack/directory.rb +77 -60
  22. data/lib/rack/etag.rb +2 -3
  23. data/lib/rack/events.rb +15 -18
  24. data/lib/rack/file.rb +1 -2
  25. data/lib/rack/files.rb +97 -57
  26. data/lib/rack/handler/cgi.rb +1 -4
  27. data/lib/rack/handler/fastcgi.rb +1 -3
  28. data/lib/rack/handler/lsws.rb +1 -3
  29. data/lib/rack/handler/scgi.rb +1 -3
  30. data/lib/rack/handler/thin.rb +1 -3
  31. data/lib/rack/handler/webrick.rb +12 -5
  32. data/lib/rack/head.rb +0 -2
  33. data/lib/rack/lint.rb +57 -14
  34. data/lib/rack/lobster.rb +3 -5
  35. data/lib/rack/lock.rb +0 -1
  36. data/lib/rack/mock.rb +22 -4
  37. data/lib/rack/multipart.rb +1 -1
  38. data/lib/rack/multipart/generator.rb +11 -6
  39. data/lib/rack/multipart/parser.rb +10 -18
  40. data/lib/rack/multipart/uploaded_file.rb +13 -7
  41. data/lib/rack/query_parser.rb +7 -8
  42. data/lib/rack/recursive.rb +1 -1
  43. data/lib/rack/reloader.rb +1 -3
  44. data/lib/rack/request.rb +182 -76
  45. data/lib/rack/response.rb +62 -19
  46. data/lib/rack/rewindable_input.rb +0 -1
  47. data/lib/rack/runtime.rb +3 -3
  48. data/lib/rack/sendfile.rb +0 -3
  49. data/lib/rack/server.rb +9 -10
  50. data/lib/rack/session/abstract/id.rb +23 -28
  51. data/lib/rack/session/cookie.rb +1 -3
  52. data/lib/rack/session/pool.rb +1 -1
  53. data/lib/rack/show_exceptions.rb +6 -8
  54. data/lib/rack/show_status.rb +5 -7
  55. data/lib/rack/static.rb +13 -6
  56. data/lib/rack/tempfile_reaper.rb +0 -2
  57. data/lib/rack/urlmap.rb +1 -4
  58. data/lib/rack/utils.rb +58 -54
  59. data/lib/rack/version.rb +29 -0
  60. data/rack.gemspec +31 -29
  61. metadata +11 -12
@@ -1,9 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'time'
4
- require 'rack/utils'
5
- require 'rack/mime'
6
- require 'rack/files'
7
4
 
8
5
  module Rack
9
6
  # Rack::Directory serves entries below the +root+ given, according to the
@@ -14,8 +11,8 @@ module Rack
14
11
  # If +app+ is not specified, a Rack::Files of the same +root+ will be used.
15
12
 
16
13
  class Directory
17
- DIR_FILE = "<tr><td class='name'><a href='%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>"
18
- DIR_PAGE = <<-PAGE
14
+ DIR_FILE = "<tr><td class='name'><a href='%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>\n"
15
+ DIR_PAGE_HEADER = <<-PAGE
19
16
  <html><head>
20
17
  <title>%s</title>
21
18
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
@@ -36,33 +33,51 @@ table { width:100%%; }
36
33
  <th class='type'>Type</th>
37
34
  <th class='mtime'>Last Modified</th>
38
35
  </tr>
39
- %s
36
+ PAGE
37
+ DIR_PAGE_FOOTER = <<-PAGE
40
38
  </table>
41
39
  <hr />
42
40
  </body></html>
43
41
  PAGE
44
42
 
43
+ # Body class for directory entries, showing an index page with links
44
+ # to each file.
45
45
  class DirectoryBody < Struct.new(:root, :path, :files)
46
+ # Yield strings for each part of the directory entry
46
47
  def each
47
- show_path = Rack::Utils.escape_html(path.sub(/^#{root}/, ''))
48
- listings = files.map{|f| DIR_FILE % DIR_FILE_escape(*f) } * "\n"
49
- page = DIR_PAGE % [ show_path, show_path, listings ]
50
- page.each_line{|l| yield l }
48
+ show_path = Utils.escape_html(path.sub(/^#{root}/, ''))
49
+ yield(DIR_PAGE_HEADER % [ show_path, show_path ])
50
+
51
+ unless path.chomp('/') == root
52
+ yield(DIR_FILE % DIR_FILE_escape(files.call('..')))
53
+ end
54
+
55
+ Dir.foreach(path) do |basename|
56
+ next if basename.start_with?('.')
57
+ next unless f = files.call(basename)
58
+ yield(DIR_FILE % DIR_FILE_escape(f))
59
+ end
60
+
61
+ yield(DIR_PAGE_FOOTER)
51
62
  end
52
63
 
53
64
  private
54
- # Assumes url is already escaped.
55
- def DIR_FILE_escape url, *html
56
- [url, *html.map { |e| Utils.escape_html(e) }]
65
+
66
+ # Escape each element in the array of html strings.
67
+ def DIR_FILE_escape(htmls)
68
+ htmls.map { |e| Utils.escape_html(e) }
57
69
  end
58
70
  end
59
71
 
60
- attr_reader :root, :path
72
+ # The root of the directory hierarchy. Only requests for files and
73
+ # directories inside of the root directory are supported.
74
+ attr_reader :root
61
75
 
76
+ # Set the root directory and application for serving files.
62
77
  def initialize(root, app = nil)
63
78
  @root = ::File.expand_path(root)
64
- @app = app || Rack::Files.new(@root)
65
- @head = Rack::Head.new(lambda { |env| get env })
79
+ @app = app || Files.new(@root)
80
+ @head = Head.new(method(:get))
66
81
  end
67
82
 
68
83
  def call(env)
@@ -70,100 +85,101 @@ table { width:100%%; }
70
85
  @head.call env
71
86
  end
72
87
 
88
+ # Internals of request handling. Similar to call but does
89
+ # not remove body for HEAD requests.
73
90
  def get(env)
74
91
  script_name = env[SCRIPT_NAME]
75
92
  path_info = Utils.unescape_path(env[PATH_INFO])
76
93
 
77
- if bad_request = check_bad_request(path_info)
78
- bad_request
79
- elsif forbidden = check_forbidden(path_info)
80
- forbidden
94
+ if client_error_response = check_bad_request(path_info) || check_forbidden(path_info)
95
+ client_error_response
81
96
  else
82
97
  path = ::File.join(@root, path_info)
83
98
  list_path(env, path, path_info, script_name)
84
99
  end
85
100
  end
86
101
 
102
+ # Rack response to use for requests with invalid paths, or nil if path is valid.
87
103
  def check_bad_request(path_info)
88
104
  return if Utils.valid_path?(path_info)
89
105
 
90
106
  body = "Bad Request\n"
91
- size = body.bytesize
92
- return [400, { CONTENT_TYPE => "text/plain",
93
- CONTENT_LENGTH => size.to_s,
107
+ [400, { CONTENT_TYPE => "text/plain",
108
+ CONTENT_LENGTH => body.bytesize.to_s,
94
109
  "X-Cascade" => "pass" }, [body]]
95
110
  end
96
111
 
112
+ # Rack response to use for requests with paths outside the root, or nil if path is inside the root.
97
113
  def check_forbidden(path_info)
98
114
  return unless path_info.include? ".."
115
+ return if ::File.expand_path(::File.join(@root, path_info)).start_with?(@root)
99
116
 
100
117
  body = "Forbidden\n"
101
- size = body.bytesize
102
- return [403, { CONTENT_TYPE => "text/plain",
103
- CONTENT_LENGTH => size.to_s,
118
+ [403, { CONTENT_TYPE => "text/plain",
119
+ CONTENT_LENGTH => body.bytesize.to_s,
104
120
  "X-Cascade" => "pass" }, [body]]
105
121
  end
106
122
 
123
+ # Rack response to use for directories under the root.
107
124
  def list_directory(path_info, path, script_name)
108
- files = [['../', 'Parent Directory', '', '', '']]
109
- glob = ::File.join(path, '*')
110
-
111
125
  url_head = (script_name.split('/') + path_info.split('/')).map do |part|
112
- Rack::Utils.escape_path part
126
+ Utils.escape_path part
113
127
  end
114
128
 
115
- Dir[glob].sort.each do |node|
116
- stat = stat(node)
129
+ # Globbing not safe as path could contain glob metacharacters
130
+ body = DirectoryBody.new(@root, path, ->(basename) do
131
+ stat = stat(::File.join(path, basename))
117
132
  next unless stat
118
- basename = ::File.basename(node)
119
- ext = ::File.extname(node)
120
133
 
121
- url = ::File.join(*url_head + [Rack::Utils.escape_path(basename)])
122
- size = stat.size
123
- type = stat.directory? ? 'directory' : Mime.mime_type(ext)
124
- size = stat.directory? ? '-' : filesize_format(size)
134
+ url = ::File.join(*url_head + [Utils.escape_path(basename)])
125
135
  mtime = stat.mtime.httpdate
126
- url << '/' if stat.directory?
127
- basename << '/' if stat.directory?
128
-
129
- files << [ url, basename, size, type, mtime ]
130
- end
131
-
132
- return [ 200, { CONTENT_TYPE => 'text/html; charset=utf-8' }, DirectoryBody.new(@root, path, files) ]
136
+ if stat.directory?
137
+ type = 'directory'
138
+ size = '-'
139
+ url << '/'
140
+ if basename == '..'
141
+ basename = 'Parent Directory'
142
+ else
143
+ basename << '/'
144
+ end
145
+ else
146
+ type = Mime.mime_type(::File.extname(basename))
147
+ size = filesize_format(stat.size)
148
+ end
149
+
150
+ [ url, basename, size, type, mtime ]
151
+ end)
152
+
153
+ [ 200, { CONTENT_TYPE => 'text/html; charset=utf-8' }, body ]
133
154
  end
134
155
 
135
- def stat(node)
136
- ::File.stat(node)
156
+ # File::Stat for the given path, but return nil for missing/bad entries.
157
+ def stat(path)
158
+ ::File.stat(path)
137
159
  rescue Errno::ENOENT, Errno::ELOOP
138
160
  return nil
139
161
  end
140
162
 
141
- # TODO: add correct response if not readable, not sure if 404 is the best
142
- # option
163
+ # Rack response to use for files and directories under the root.
164
+ # Unreadable and non-file, non-directory entries will get a 404 response.
143
165
  def list_path(env, path, path_info, script_name)
144
- stat = ::File.stat(path)
145
-
146
- if stat.readable?
166
+ if (stat = stat(path)) && stat.readable?
147
167
  return @app.call(env) if stat.file?
148
168
  return list_directory(path_info, path, script_name) if stat.directory?
149
- else
150
- raise Errno::ENOENT, 'No such file or directory'
151
169
  end
152
170
 
153
- rescue Errno::ENOENT, Errno::ELOOP
154
- return entity_not_found(path_info)
171
+ entity_not_found(path_info)
155
172
  end
156
173
 
174
+ # Rack response to use for unreadable and non-file, non-directory entries.
157
175
  def entity_not_found(path_info)
158
176
  body = "Entity not found: #{path_info}\n"
159
- size = body.bytesize
160
- return [404, { CONTENT_TYPE => "text/plain",
161
- CONTENT_LENGTH => size.to_s,
177
+ [404, { CONTENT_TYPE => "text/plain",
178
+ CONTENT_LENGTH => body.bytesize.to_s,
162
179
  "X-Cascade" => "pass" }, [body]]
163
180
  end
164
181
 
165
182
  # Stolen from Ramaze
166
-
167
183
  FILESIZE_FORMAT = [
168
184
  ['%.1fT', 1 << 40],
169
185
  ['%.1fG', 1 << 30],
@@ -171,6 +187,7 @@ table { width:100%%; }
171
187
  ['%.1fK', 1 << 10],
172
188
  ]
173
189
 
190
+ # Provide human readable file sizes
174
191
  def filesize_format(int)
175
192
  FILESIZE_FORMAT.each do |format, size|
176
193
  return format % (int.to_f / size) if int >= size
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rack'
3
+ require_relative '../rack'
4
4
  require 'digest/sha2'
5
5
 
6
6
  module Rack
@@ -57,8 +57,7 @@ module Rack
57
57
  end
58
58
 
59
59
  def skip_caching?(headers)
60
- (headers[CACHE_CONTROL] && headers[CACHE_CONTROL].include?('no-cache')) ||
61
- headers.key?(ETAG_STRING) || headers.key?('Last-Modified')
60
+ headers.key?(ETAG_STRING) || headers.key?('Last-Modified')
62
61
  end
63
62
 
64
63
  def digest_body(body)
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rack/response'
4
- require 'rack/body_proxy'
5
-
6
3
  module Rack
7
4
  ### This middleware provides hooks to certain places in the request /
8
5
  # response lifecycle. This is so that middleware that don't need to filter
@@ -59,26 +56,26 @@ module Rack
59
56
 
60
57
  class Events
61
58
  module Abstract
62
- def on_start req, res
59
+ def on_start(req, res)
63
60
  end
64
61
 
65
- def on_commit req, res
62
+ def on_commit(req, res)
66
63
  end
67
64
 
68
- def on_send req, res
65
+ def on_send(req, res)
69
66
  end
70
67
 
71
- def on_finish req, res
68
+ def on_finish(req, res)
72
69
  end
73
70
 
74
- def on_error req, res, e
71
+ def on_error(req, res, e)
75
72
  end
76
73
  end
77
74
 
78
75
  class EventedBodyProxy < Rack::BodyProxy # :nodoc:
79
76
  attr_reader :request, :response
80
77
 
81
- def initialize body, request, response, handlers, &block
78
+ def initialize(body, request, response, handlers, &block)
82
79
  super(body, &block)
83
80
  @request = request
84
81
  @response = response
@@ -94,7 +91,7 @@ module Rack
94
91
  class BufferedResponse < Rack::Response::Raw # :nodoc:
95
92
  attr_reader :body
96
93
 
97
- def initialize status, headers, body
94
+ def initialize(status, headers, body)
98
95
  super(status, headers)
99
96
  @body = body
100
97
  end
@@ -102,12 +99,12 @@ module Rack
102
99
  def to_a; [status, headers, body]; end
103
100
  end
104
101
 
105
- def initialize app, handlers
102
+ def initialize(app, handlers)
106
103
  @app = app
107
104
  @handlers = handlers
108
105
  end
109
106
 
110
- def call env
107
+ def call(env)
111
108
  request = make_request env
112
109
  on_start request, nil
113
110
 
@@ -129,27 +126,27 @@ module Rack
129
126
 
130
127
  private
131
128
 
132
- def on_error request, response, e
129
+ def on_error(request, response, e)
133
130
  @handlers.reverse_each { |handler| handler.on_error request, response, e }
134
131
  end
135
132
 
136
- def on_commit request, response
133
+ def on_commit(request, response)
137
134
  @handlers.reverse_each { |handler| handler.on_commit request, response }
138
135
  end
139
136
 
140
- def on_start request, response
137
+ def on_start(request, response)
141
138
  @handlers.each { |handler| handler.on_start request, nil }
142
139
  end
143
140
 
144
- def on_finish request, response
141
+ def on_finish(request, response)
145
142
  @handlers.reverse_each { |handler| handler.on_finish request, response }
146
143
  end
147
144
 
148
- def make_request env
145
+ def make_request(env)
149
146
  Rack::Request.new env
150
147
  end
151
148
 
152
- def make_response status, headers, body
149
+ def make_response(status, headers, body)
153
150
  BufferedResponse.new status, headers, body
154
151
  end
155
152
  end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rack/files'
3
+ require_relative 'files'
4
4
 
5
5
  module Rack
6
- warn "Rack::File is deprecated, please use Rack::Files instead."
7
6
  File = Files
8
7
  end
@@ -1,10 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'time'
4
- require 'rack/utils'
5
- require 'rack/mime'
6
- require 'rack/request'
7
- require 'rack/head'
8
4
 
9
5
  module Rack
10
6
  # Rack::Files serves files below the +root+ directory given, according to the
@@ -18,11 +14,20 @@ module Rack
18
14
  class Files
19
15
  ALLOWED_VERBS = %w[GET HEAD OPTIONS]
20
16
  ALLOW_HEADER = ALLOWED_VERBS.join(', ')
17
+ MULTIPART_BOUNDARY = 'AaB03x'
18
+
19
+ # @todo remove in 3.0
20
+ def self.method_added(name)
21
+ if name == :response_body
22
+ raise "#{self.class}\#response_body is no longer supported."
23
+ end
24
+ super
25
+ end
21
26
 
22
27
  attr_reader :root
23
28
 
24
29
  def initialize(root, headers = {}, default_mime = 'text/plain')
25
- @root = ::File.expand_path root
30
+ @root = (::File.expand_path(root) if root)
26
31
  @headers = headers
27
32
  @default_mime = default_mime
28
33
  @head = Rack::Head.new(lambda { |env| get env })
@@ -48,7 +53,11 @@ module Rack
48
53
  available = begin
49
54
  ::File.file?(path) && ::File.readable?(path)
50
55
  rescue SystemCallError
56
+ # Not sure in what conditions this exception can occur, but this
57
+ # is a safe way to handle such an error.
58
+ # :nocov:
51
59
  false
60
+ # :nocov:
52
61
  end
53
62
 
54
63
  if available
@@ -70,75 +79,116 @@ module Rack
70
79
  headers[CONTENT_TYPE] = mime_type if mime_type
71
80
 
72
81
  # Set custom headers
73
- @headers.each { |field, content| headers[field] = content } if @headers
74
-
75
- response = [ 200, headers ]
82
+ headers.merge!(@headers) if @headers
76
83
 
84
+ status = 200
77
85
  size = filesize path
78
86
 
79
- range = nil
80
87
  ranges = Rack::Utils.get_byte_ranges(request.get_header('HTTP_RANGE'), size)
81
- if ranges.nil? || ranges.length > 1
82
- # No ranges, or multiple ranges (which we don't support):
83
- # TODO: Support multiple byte-ranges
84
- response[0] = 200
85
- range = 0..size - 1
88
+ if ranges.nil?
89
+ # No ranges:
90
+ ranges = [0..size - 1]
86
91
  elsif ranges.empty?
87
92
  # Unsatisfiable. Return error, and file size:
88
93
  response = fail(416, "Byte range unsatisfiable")
89
94
  response[1]["Content-Range"] = "bytes */#{size}"
90
95
  return response
91
- else
92
- # Partial content:
93
- range = ranges[0]
94
- response[0] = 206
95
- response[1]["Content-Range"] = "bytes #{range.begin}-#{range.end}/#{size}"
96
- size = range.end - range.begin + 1
96
+ elsif ranges.size >= 1
97
+ # Partial content
98
+ partial_content = true
99
+
100
+ if ranges.size == 1
101
+ range = ranges[0]
102
+ headers["Content-Range"] = "bytes #{range.begin}-#{range.end}/#{size}"
103
+ else
104
+ headers[CONTENT_TYPE] = "multipart/byteranges; boundary=#{MULTIPART_BOUNDARY}"
105
+ end
106
+
107
+ status = 206
108
+ body = BaseIterator.new(path, ranges, mime_type: mime_type, size: size)
109
+ size = body.bytesize
97
110
  end
98
111
 
99
- response[2] = [response_body] unless response_body.nil?
112
+ headers[CONTENT_LENGTH] = size.to_s
100
113
 
101
- response[1][CONTENT_LENGTH] = size.to_s
102
- response[2] = make_body request, path, range
103
- response
114
+ if request.head?
115
+ body = []
116
+ elsif !partial_content
117
+ body = Iterator.new(path, ranges, mime_type: mime_type, size: size)
118
+ end
119
+
120
+ [status, headers, body]
104
121
  end
105
122
 
106
- class Iterator
107
- attr_reader :path, :range
108
- alias :to_path :path
123
+ class BaseIterator
124
+ attr_reader :path, :ranges, :options
109
125
 
110
- def initialize path, range
111
- @path = path
112
- @range = range
126
+ def initialize(path, ranges, options)
127
+ @path = path
128
+ @ranges = ranges
129
+ @options = options
113
130
  end
114
131
 
115
132
  def each
116
133
  ::File.open(path, "rb") do |file|
117
- file.seek(range.begin)
118
- remaining_len = range.end - range.begin + 1
119
- while remaining_len > 0
120
- part = file.read([8192, remaining_len].min)
121
- break unless part
122
- remaining_len -= part.length
123
-
124
- yield part
134
+ ranges.each do |range|
135
+ yield multipart_heading(range) if multipart?
136
+
137
+ each_range_part(file, range) do |part|
138
+ yield part
139
+ end
125
140
  end
141
+
142
+ yield "\r\n--#{MULTIPART_BOUNDARY}--\r\n" if multipart?
126
143
  end
127
144
  end
128
145
 
146
+ def bytesize
147
+ size = ranges.inject(0) do |sum, range|
148
+ sum += multipart_heading(range).bytesize if multipart?
149
+ sum += range.size
150
+ end
151
+ size += "\r\n--#{MULTIPART_BOUNDARY}--\r\n".bytesize if multipart?
152
+ size
153
+ end
154
+
129
155
  def close; end
130
- end
131
156
 
132
- private
157
+ private
133
158
 
134
- def make_body request, path, range
135
- if request.head?
136
- []
137
- else
138
- Iterator.new path, range
159
+ def multipart?
160
+ ranges.size > 1
161
+ end
162
+
163
+ def multipart_heading(range)
164
+ <<-EOF
165
+ \r
166
+ --#{MULTIPART_BOUNDARY}\r
167
+ Content-Type: #{options[:mime_type]}\r
168
+ Content-Range: bytes #{range.begin}-#{range.end}/#{options[:size]}\r
169
+ \r
170
+ EOF
171
+ end
172
+
173
+ def each_range_part(file, range)
174
+ file.seek(range.begin)
175
+ remaining_len = range.end - range.begin + 1
176
+ while remaining_len > 0
177
+ part = file.read([8192, remaining_len].min)
178
+ break unless part
179
+ remaining_len -= part.length
180
+
181
+ yield part
182
+ end
139
183
  end
140
184
  end
141
185
 
186
+ class Iterator < BaseIterator
187
+ alias :to_path :path
188
+ end
189
+
190
+ private
191
+
142
192
  def fail(status, body, headers = {})
143
193
  body += "\n"
144
194
 
@@ -154,25 +204,15 @@ module Rack
154
204
  end
155
205
 
156
206
  # The MIME type for the contents of the file located at @path
157
- def mime_type path, default_mime
207
+ def mime_type(path, default_mime)
158
208
  Mime.mime_type(::File.extname(path), default_mime)
159
209
  end
160
210
 
161
- def filesize path
162
- # If response_body is present, use its size.
163
- return response_body.bytesize if response_body
164
-
211
+ def filesize(path)
165
212
  # We check via File::size? whether this file provides size info
166
213
  # via stat (e.g. /proc files often don't), otherwise we have to
167
214
  # figure it out by reading the whole file into memory.
168
215
  ::File.size?(path) || ::File.read(path).bytesize
169
216
  end
170
-
171
- # By default, the response body for file requests is nil.
172
- # In this case, the response body will be generated later
173
- # from the file at @path
174
- def response_body
175
- nil
176
- end
177
217
  end
178
218
  end