Module: Typhoeus::Request::Streamable

Included in:
Typhoeus::Request
Defined in:
lib/typhoeus/request/streamable.rb

Overview

This module contians the logic for response streaming.

Since:

  • 0.5.0

Instance Method Summary collapse

Instance Method Details

#on_body(&block) {|Typhoeus::Response, String| ... } ⇒ Array<Block>

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.

Examples:

Set on_body.

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

Parameters:

  • block (Block)

    The block to execute.

Yields:

Returns:

  • (Array<Block>)

    All on_body blocks.

Since:

  • 0.5.0



20
21
22
23
24
# File 'lib/typhoeus/request/streamable.rb', line 20

def on_body(&block)
  @on_body ||= []
  @on_body << block if block_given?
  @on_body
end

#streaming?Boolean

Is this request using streaming?

Returns:

  • (Boolean)

    True if any on_body blocks have been set.

Since:

  • 0.5.0



29
30
31
# File 'lib/typhoeus/request/streamable.rb', line 29

def streaming?
  defined?(@on_body) && @on_body.any?
end