module Typhoeus::Request::Streamable

This module contians the logic for response streaming.

Public Instance Methods

on_body(&block) click to toggle source

Set #on_body callback.

This callback will be called each time a portion of the body is read from the socket. Setting an #on_body callback will cause the response body to be empty.

@example Set on_body.

request.on_body { |response, body_chunk| puts "Got #{body_chunk.bytesize} bytes" }

@param [ Block ] block The block to execute.

@yield [ Typhoeus::Response, String ]

@return [ Array<Block> ] All #on_body blocks.

# File lib/typhoeus/request/streamable.rb, line 20
def on_body(&block)
  @on_body ||= []
  @on_body << block if block_given?
  @on_body
end
streaming?() click to toggle source

Is this request using streaming?

@return [ Boolean ] True if any #on_body blocks have been set.

# File lib/typhoeus/request/streamable.rb, line 29
def streaming?
  defined?(@on_body) && @on_body.any?
end