simplify initialization of request buffer

This commit is contained in:
HoneyryderChuck 2023-10-23 17:54:11 +01:00
parent d5e469d6c6
commit c5fc8aeb19

View File

@ -13,7 +13,7 @@ module HTTPX
@threshold_size = threshold_size
@bytesize = bytesize
@encoding = encoding
try_upgrade_buffer
@buffer = StringIO.new("".b)
super(@buffer)
end
@ -66,7 +66,10 @@ module HTTPX
# initializes the buffer into a StringIO, or turns it into a Tempfile when the threshold
# has been reached.
def try_upgrade_buffer
if !@buffer.is_a?(Tempfile) && @bytesize > @threshold_size
return unless @bytesize > @threshold_size
return if @buffer.is_a?(Tempfile)
aux = @buffer
@buffer = Tempfile.new("httpx", encoding: Encoding::BINARY, mode: File::RDWR)
@ -77,12 +80,6 @@ module HTTPX
aux.close
end
else
return if @buffer
@buffer = StringIO.new("".b)
end
__setobj__(@buffer)
end