diff --git a/bin/passenger-install-nginx-module b/bin/passenger-install-nginx-module index d87f0532d4..f1aea858ff 100755 --- a/bin/passenger-install-nginx-module +++ b/bin/passenger-install-nginx-module @@ -603,12 +603,7 @@ private # We do this instead of using #file, for Ruby 1.8.5 support. digest = Digest::SHA256.new File.open(path, "rb") do |f| - if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0') - buf = String.new(encoding: Encoding::BINARY) - else - buf = "" - buf.force_encoding('binary') if buf.respond_to?(:force_encoding) - end + buf = ''.b while !f.eof? f.read(1024 * 16, buf) digest.update(buf) diff --git a/dev/ruby_server.rb b/dev/ruby_server.rb index c5509679af..8e686ebc4a 100755 --- a/dev/ruby_server.rb +++ b/dev/ruby_server.rb @@ -135,12 +135,7 @@ def start_thread def handle_next_client(forward_connection) client = @server.accept begin - if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0') - buffer = String.new(encoding: Encoding::BINARY) - else - buffer = "" - buffer.force_encoding('binary') if buffer.respond_to?(:force_encoding) - end + buffer = "".b while true begin read_header(client, buffer) diff --git a/src/ruby_supportlib/phusion_passenger/admin_tools/memory_stats.rb b/src/ruby_supportlib/phusion_passenger/admin_tools/memory_stats.rb index 622876c869..8e4c02b4df 100644 --- a/src/ruby_supportlib/phusion_passenger/admin_tools/memory_stats.rb +++ b/src/ruby_supportlib/phusion_passenger/admin_tools/memory_stats.rb @@ -250,7 +250,7 @@ def list_processes(options) ps_output = `#{ps} -w -o pid,ppid,nlwp,vsz,rss,%cpu,command` threads_known = true end - list = force_binary(ps_output).split("\n") + list = ps_output.b.split("\n") list.shift list.each do |line| line.gsub!(/^ */, '') @@ -297,16 +297,6 @@ def determine_private_dirty_rss(pid) rescue Errno::EACCES, Errno::ENOENT, Errno::ESRCH return nil end - - if ''.respond_to?(:force_encoding) - def force_binary(str) - str.force_encoding('binary') - end - else - def force_binary(str) - str - end - end end end # module AdminTools diff --git a/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb b/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb index d537edacd3..adaf88d592 100644 --- a/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb +++ b/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb @@ -101,12 +101,7 @@ def install def main_loop(finish_callback) socket_wrapper = Utils::UnseekableSocket.new channel = MessageChannel.new - if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0') - buffer = String.new(encoding: Encoding::BINARY) - else - buffer = "" - buffer.force_encoding('binary') if buffer.respond_to?(:force_encoding) - end + buffer = ''.b begin finish_callback.call diff --git a/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb b/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb index 65ee121e38..3ed06fffe9 100644 --- a/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +++ b/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb @@ -322,12 +322,8 @@ def default_group_for(username) end def serialize_strset(*items) - if "".respond_to?(:force_encoding) - items = items.map { |x| x.force_encoding('binary') } - null = "\0".force_encoding('binary') - else - null = "\0" - end + items = items.map(&:b) + null = "\0".b return [items.join(null)].pack('m*').gsub("\n", "").strip end diff --git a/src/ruby_supportlib/phusion_passenger/utils/unseekable_socket.rb b/src/ruby_supportlib/phusion_passenger/utils/unseekable_socket.rb index a493214119..875cda38ce 100644 --- a/src/ruby_supportlib/phusion_passenger/utils/unseekable_socket.rb +++ b/src/ruby_supportlib/phusion_passenger/utils/unseekable_socket.rb @@ -180,9 +180,9 @@ def gets if @simulate_eof length, buffer = args if buffer - buffer.replace(binary_string("")) + buffer.replace("".b) else - buffer = binary_string("") + buffer = "".b end if length return nil @@ -292,16 +292,6 @@ def annotate(exception) def raise_error_because_activity_disallowed! raise IOError, "It is not possible to read or write from the client socket because the current." end - - if ''.respond_to?(:force_encoding) - def binary_string(str) - return ''.force_encoding('binary') - end - else - def binary_string(str) - return '' - end - end end end # module Utils diff --git a/test/integration_tests/native_packaging_spec.rb b/test/integration_tests/native_packaging_spec.rb index 3e86fe6c7e..0893abc952 100644 --- a/test/integration_tests/native_packaging_spec.rb +++ b/test/integration_tests/native_packaging_spec.rb @@ -135,9 +135,8 @@ module PhusionPassenger describe "A natively packaged Phusion Passenger" do def capture_output(command) output = `#{command}`.strip - if output.respond_to?(:force_encoding) - output.force_encoding('utf-8') - end + output.force_encoding(Encoding::UTF_8) + if $?.exitstatus == 0 return output else diff --git a/test/integration_tests/shared/example_webapp_tests.rb b/test/integration_tests/shared/example_webapp_tests.rb index 7764659c61..647f141014 100644 --- a/test/integration_tests/shared/example_webapp_tests.rb +++ b/test/integration_tests/shared/example_webapp_tests.rb @@ -64,9 +64,9 @@ io.read end response.should == - binary_string("name 1 = Kotonoha\n") << - binary_string("name 2 = Sekai\n") << - binary_string("data = ") << static_file.read + "name 1 = Kotonoha\n".b << + "name 2 = Sekai\n".b << + "data = ".b << static_file.read ensure static_file.close end diff --git a/test/integration_tests/standalone_tests.rb b/test/integration_tests/standalone_tests.rb index 39073125bb..22d0f61c43 100644 --- a/test/integration_tests/standalone_tests.rb +++ b/test/integration_tests/standalone_tests.rb @@ -32,9 +32,8 @@ def sh(*command) def capture_output(command) output = `#{command} 2>&1`.strip - if output.respond_to?(:force_encoding) - output.force_encoding('utf-8') - end + output.force_encoding(Encoding::UTF_8) + if $?.exitstatus == 0 output else diff --git a/test/stub/rack/config.ru b/test/stub/rack/config.ru index 39a3605c2b..2722954711 100644 --- a/test/stub/rack/config.ru +++ b/test/stub/rack/config.ru @@ -50,8 +50,8 @@ app = lambda do |env| text_response("This is the uncached version of /cached") when '/upload_with_params' req = Rack::Request.new(env) - name1 = binary_string(req.params["name1"]) - name2 = binary_string(req.params["name2"]) + name1 = req.params["name1"].b + name2 = req.params["name2"].b file = req.params["data"][:tempfile] file.binmode text_response( diff --git a/test/stub/rack/library.rb b/test/stub/rack/library.rb index 7992ef4c16..42085ff272 100644 --- a/test/stub/rack/library.rb +++ b/test/stub/rack/library.rb @@ -1,16 +1,6 @@ # encoding: binary def text_response(body) - body = binary_string(body.to_s) + body = body.to_s.b return [200, { "Content-Type" => "text/plain", "Content-Length" => body.size.to_s }, [body]] end - -if "".respond_to?(:force_encoding) - def binary_string(str) - return str.force_encoding("binary") - end -else - def binary_string(str) - return str - end -end diff --git a/test/support/test_helper.rb b/test/support/test_helper.rb index 5200d2f8cd..7a3c951208 100644 --- a/test/support/test_helper.rb +++ b/test/support/test_helper.rb @@ -350,16 +350,6 @@ def inspect_server(name) return instance end end - - if "".respond_to?(:force_encoding) - def binary_string(str) - return str.force_encoding("binary") - end - else - def binary_string(str) - return str - end - end end File.class_eval do