Class: HTTP::Response::Streamer

Inherits:
Object
  • Object
show all
Defined in:
lib/webmock/http_lib_adapters/http_rb/streamer.rb

Instance Method Summary collapse

Constructor Details

#initialize(str, encoding: Encoding::BINARY) ⇒ Streamer

Returns a new instance of Streamer.



6
7
8
9
# File 'lib/webmock/http_lib_adapters/http_rb/streamer.rb', line 6

def initialize(str, encoding: Encoding::BINARY)
  @io = StringIO.new str
  @encoding = encoding
end

Instance Method Details

#closeObject



31
32
33
# File 'lib/webmock/http_lib_adapters/http_rb/streamer.rb', line 31

def close
  @io.close
end

#finished_request?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/webmock/http_lib_adapters/http_rb/streamer.rb', line 35

def finished_request?
  @io.eof?
end

#readpartial(size = nil, outbuf = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/webmock/http_lib_adapters/http_rb/streamer.rb', line 11

def readpartial(size = nil, outbuf = nil)
  unless size
    if defined?(HTTP::Connection::BUFFER_SIZE)
      size = HTTP::Connection::BUFFER_SIZE
    elsif defined?(HTTP::Client::BUFFER_SIZE)
      size = HTTP::Client::BUFFER_SIZE
    end
  end

  chunk = @io.read(size, outbuf)

  # HTTP.rb 6.0+ expects EOFError at end-of-stream instead of nil
  if chunk.nil?
    raise EOFError if HTTP::VERSION >= "6.0.0"
    return nil
  end

  chunk.force_encoding(@encoding)
end

#sequence_idObject



39
40
41
# File 'lib/webmock/http_lib_adapters/http_rb/streamer.rb', line 39

def sequence_id
  -1
end