Class: Http2::ResponseReader
- Inherits:
-
Object
- Object
- Http2::ResponseReader
- Defined in:
- lib/http2/response_reader.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(args) ⇒ ResponseReader
constructor
A new instance of ResponseReader.
- #read_body ⇒ Object
- #read_headers ⇒ Object
Constructor Details
#initialize(args) ⇒ ResponseReader
Returns a new instance of ResponseReader.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/http2/response_reader.rb', line 4 def initialize(args) @mode = "headers" @transfer_encoding = nil @response = Http2::Response.new(request: args.fetch(:request), request_args: args, debug: @debug) @rec_count = 0 @args = args[:args] @debug = args[:http2].debug @http2 = args[:http2] @sock = args[:sock] @nl = @http2.nl @conn = @http2.connection read_headers read_body if @length == nil || @length > 0 finish end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
2 3 4 |
# File 'lib/http2/response_reader.rb', line 2 def response @response end |
Instance Method Details
#finish ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/http2/response_reader.rb', line 54 def finish # Check if we should reconnect based on keep-alive-max. if @keepalive_max == 1 || @connection == "close" @conn.close unless @conn.closed? end # Validate that the response is as it should be. puts "Http2: Validating response." if @debug unless @response.code raise "No status-code was received from the server. Headers: '#{@response.headers}' Body: '#{@response.body}'." end @response.validate! check_and_decode @http2.autostate_register(@response) if @http2.args[:autostate] handle_errors if (response = check_and_follow_redirect) @response = response end end |
#read_body ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/http2/response_reader.rb', line 38 def read_body loop do if @length line = @conn.read(@length) raise "Expected to get #{@length} of bytes but got #{line.bytesize}" if @length != line.bytesize else line = @conn.gets end check_line_read(line) stat = parse_body(line) break if stat == :break next if stat == :next end end |
#read_headers ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/http2/response_reader.rb', line 21 def read_headers loop do line = @conn.gets check_line_read(line) if line == "\n" || line == "\r\n" || line == @nl puts "Http2: Changing mode to body!" if @debug raise "No headers was given at all? Possibly corrupt state after last request?" if @response.headers.empty? @mode = "body" @http2.on_content_call(@args, @nl) break end parse_header(line) end end |