From 66c4ed7957459de270cffedfd494562359386d4e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 1 Jun 2023 21:19:35 +0000 Subject: chunk unterminated HTTP/1.1 responses Rack::Chunked will be gone in Rack 3.1, so provide a non-middleware fallback which takes advantage of IO#write supporting multiple arguments in Ruby 2.5+. We still need to support Ruby 2.4, at least, since Rack 3.0 does. So a new (GC-unfriendly) Unicorn::WriteSplat module now exists for Ruby <= 2.4 users. --- lib/unicorn/socket_helper.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'lib/unicorn/socket_helper.rb') diff --git a/lib/unicorn/socket_helper.rb b/lib/unicorn/socket_helper.rb index 8a6f6ee..c2ba75e 100644 --- a/lib/unicorn/socket_helper.rb +++ b/lib/unicorn/socket_helper.rb @@ -15,6 +15,20 @@ module Unicorn end end + if IO.instance_method(:write).arity == 1 # Ruby <= 2.4 + require 'unicorn/write_splat' + UNIXClient = Class.new(Kgio::Socket) # :nodoc: + class UNIXSrv < Kgio::UNIXServer # :nodoc: + include Unicorn::WriteSplat + def kgio_tryaccept # :nodoc: + super(UNIXClient) + end + end + TCPClient.__send__(:include, Unicorn::WriteSplat) + else # Ruby 2.5+ + UNIXSrv = Kgio::UNIXServer + end + module SocketHelper # internal interface @@ -135,7 +149,7 @@ module Unicorn end old_umask = File.umask(opt[:umask] || 0) begin - Kgio::UNIXServer.new(address) + UNIXSrv.new(address) ensure File.umask(old_umask) end @@ -203,7 +217,7 @@ module Unicorn Socket.unpack_sockaddr_in(sock.getsockname) TCPSrv.for_fd(sock.fileno) rescue ArgumentError - Kgio::UNIXServer.for_fd(sock.fileno) + UNIXSrv.for_fd(sock.fileno) end end -- cgit v1.2.3-24-ge0c7