mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-11-13 00:01:28 -05:00
simplify initialization of request buffer
This commit is contained in:
parent
d5e469d6c6
commit
c5fc8aeb19
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user