Class: Net::WebMockNetBufferedIO
- Inherits:
-
BufferedIO
- Object
- BufferedIO
- Net::WebMockNetBufferedIO
- Defined in:
- lib/webmock/http_lib_adapters/net_http.rb
Instance Method Summary collapse
-
#initialize(io, *args, **kwargs) ⇒ WebMockNetBufferedIO
constructor
A new instance of WebMockNetBufferedIO.
-
#rbuf_fill ⇒ Object
github.com/ruby/ruby/blob/7d02441f0d6e5c9d0a73a024519eba4f69e36dce/lib/net/protocol.rb#L208 Modified version of method from ruby, so that nil is always passed into orig_read_nonblock to avoid timeout.
Constructor Details
#initialize(io, *args, **kwargs) ⇒ WebMockNetBufferedIO
Returns a new instance of WebMockNetBufferedIO.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/webmock/http_lib_adapters/net_http.rb', line 267 def initialize(io, *args, **kwargs) io = case io when Socket, OpenSSL::SSL::SSLSocket, IO io when StringIO PatchedStringIO.new(io.string) when String PatchedStringIO.new(io) end raise "Unable to create local socket" unless io # Prior to 2.4.0 `BufferedIO` only takes a single argument (`io`) with no # options. Here we pass through our full set of arguments only if we're # on 2.4.0 or later, and use a simplified invocation otherwise. if RUBY_VERSION >= '2.4.0' super else super(io) end end |
Instance Method Details
#rbuf_fill ⇒ Object
github.com/ruby/ruby/blob/7d02441f0d6e5c9d0a73a024519eba4f69e36dce/lib/net/protocol.rb#L208 Modified version of method from ruby, so that nil is always passed into orig_read_nonblock to avoid timeout
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/webmock/http_lib_adapters/net_http.rb', line 291 def rbuf_fill case rv = @io.read_nonblock(BUFSIZE, nil, exception: false) when String return if rv.nil? @rbuf << rv rv.clear return when :wait_readable @io.to_io.wait_readable(@read_timeout) or raise Net::ReadTimeout when :wait_writable @io.to_io.wait_writable(@read_timeout) or raise Net::ReadTimeout when nil raise EOFError, 'end of file reached' end while true end |