Skip to content

Commit

Permalink
Merge pull request #252 from jlahtinen/master
Browse files Browse the repository at this point in the history
Remove usage of Rack::Utils.bytesize
  • Loading branch information
headius authored Jun 17, 2024
2 parents a965a33 + 8cba783 commit 06f2451
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/main/ruby/jruby/rack/error_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ def serve(code, path, env)
headers = { 'Last-Modified' => last_modified }
DEFAULT_HEADERS.each { |field, content| headers[field] = content }
ext = File.extname(path)
size = File.size?(path)
mime = ::Rack::Mime.mime_type(ext, DEFAULT_MIME) if defined?(::Rack::Mime)
mime = 'text/html' if ! mime && ( ext == '.html' || ext == '.htm' )
headers['Content-Type'] = mime if mime

body = env['REQUEST_METHOD'] == 'HEAD' ? [] : FileBody.new(path, size = File.size?(path))
body = env['REQUEST_METHOD'] == 'HEAD' ? [] : FileBody.new(path, size)
response = [ code, headers, body ]

size ||= ::Rack::Utils.bytesize(File.read(path)) if defined?(::Rack::Utils.bytesize)

response[1]['Content-Length'] = size.to_s if size
response
end
Expand Down Expand Up @@ -169,4 +168,4 @@ def http_accept?(env, mime)

end
end
end
end
2 changes: 1 addition & 1 deletion src/main/ruby/jruby/rack/error_app/show_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def call(env)
detail = detail = env["rack.showstatus.detail"] || message

body = @template.result(binding)
size = ::Rack::Utils.bytesize(body)
size = body.bytesize
[status, headers.merge('Content-Type' => "text/html", 'Content-Length' => size.to_s), [body]]
else
[status, headers, body]
Expand Down

0 comments on commit 06f2451

Please sign in to comment.