lib/httpx/response.rb in httpx-0.18.7 vs lib/httpx/response.rb in httpx-0.19.0
- old
+ new
@@ -171,11 +171,11 @@
begin
@buffer.string.force_encoding(@encoding)
rescue ArgumentError
@buffer.string
end
- when Tempfile, File
+ when Tempfile
rewind
content = _with_same_buffer_pos { @buffer.read }
begin
content.force_encoding(@encoding)
rescue ArgumentError # ex: unknown encoding name - utf
@@ -251,10 +251,11 @@
else
@state = :memory
@buffer = StringIO.new("".b)
end
when :memory
+ # @type ivar @buffer: StringIO | Tempfile
if @length > @threshold_size
aux = @buffer
@buffer = Tempfile.new("httpx", encoding: Encoding::BINARY, mode: File::RDWR)
aux.rewind
::IO.copy_stream(aux, @buffer)
@@ -270,14 +271,15 @@
end
def _with_same_buffer_pos
return yield unless @buffer && @buffer.respond_to?(:pos)
+ # @type ivar @buffer: StringIO | Tempfile
current_pos = @buffer.pos
@buffer.rewind
begin
yield
- rescue StandardError
+ ensure
@buffer.pos = current_pos
end
end
end
end