File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -86,9 +86,11 @@ def send_request(req)
8686 def readpartial ( size = BUFFER_SIZE )
8787 return unless @pending_response
8888
89+ chunk = @parser . get_chunk ( size )
90+ return chunk if chunk
91+
8992 finished = ( read_more ( size ) == :eof ) || @parser . finished?
9093 chunk = @parser . chunk
91-
9294 finish_response if finished
9395
9496 chunk . to_s
Original file line number Diff line number Diff line change 33module HTTP
44 class Response
55 class Parser
6- attr_reader :headers
6+ attr_reader :headers , :chunk
77
88 def initialize
99 @parser = HTTP ::Parser . new ( self )
@@ -43,9 +43,17 @@ def on_body(chunk)
4343 end
4444 end
4545
46- def chunk
47- chunk = @chunk
48- @chunk = nil
46+ def get_chunk ( size )
47+ return if @chunk . nil?
48+
49+ if @chunk . bytesize <= size
50+ chunk = @chunk
51+ @chunk = nil
52+ else
53+ chunk = @chunk . byteslice ( 0 , size )
54+ @chunk [ 0 , size ] = ""
55+ end
56+
4957 chunk
5058 end
5159
You can’t perform that action at this time.
0 commit comments