Public Class methods
new(request, session)
[show source]
# File lib/httpx/plugins/stream.rb 5 def initialize(request, session) 6 @request = request 7 @session = session 8 @response = nil 9 end
Public Instance methods
each(&block)
[show source]
# File lib/httpx/plugins/stream.rb 11 def each(&block) 12 return enum_for(__method__) unless block 13 14 @request.stream = self 15 16 begin 17 @on_chunk = block 18 19 if @request.response 20 # if we've already started collecting the payload, yield it first 21 # before proceeding. 22 body = @request.response.body 23 24 body.each do |chunk| 25 on_chunk(chunk) 26 end 27 end 28 29 response.raise_for_status 30 ensure 31 @on_chunk = nil 32 end 33 end
each_line()
[show source]
# File lib/httpx/plugins/stream.rb 35 def each_line 36 return enum_for(__method__) unless block_given? 37 38 line = "".b 39 40 each do |chunk| 41 line << chunk 42 43 while (idx = line.index("\n")) 44 yield line.byteslice(0..idx - 1) 45 46 line = line.byteslice(idx + 1..-1) 47 end 48 end 49 50 yield line unless line.empty? 51 end
inspect()
:nocov:
[show source]
# File lib/httpx/plugins/stream.rb 61 def inspect 62 "#<StreamResponse:#{object_id}>" 63 end
on_chunk(chunk)
This is a ghost method. It’s to be used ONLY internally, when processing streams
[show source]
# File lib/httpx/plugins/stream.rb 54 def on_chunk(chunk) 55 raise NoMethodError unless @on_chunk 56 57 @on_chunk.call(chunk) 58 end