Commit 800c581 1 parent 1469007 commit 800c581 Copy full SHA for 800c581
File tree 2 files changed +15
-5
lines changed
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)
86
86
def readpartial ( size = BUFFER_SIZE )
87
87
return unless @pending_response
88
88
89
+ chunk = @parser . get_chunk ( size )
90
+ return chunk if chunk
91
+
89
92
finished = ( read_more ( size ) == :eof ) || @parser . finished?
90
93
chunk = @parser . chunk
91
-
92
94
finish_response if finished
93
95
94
96
chunk . to_s
Original file line number Diff line number Diff line change 3
3
module HTTP
4
4
class Response
5
5
class Parser
6
- attr_reader :headers
6
+ attr_reader :headers , :chunk
7
7
8
8
def initialize
9
9
@parser = HTTP ::Parser . new ( self )
@@ -43,9 +43,17 @@ def on_body(chunk)
43
43
end
44
44
end
45
45
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
+
49
57
chunk
50
58
end
51
59
You can’t perform that action at this time.
0 commit comments