Class: TestPuma::Response
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Class Chain: 
          self,
          String
         | |
| Instance Chain: 
          self,
          String
         | |
| Inherits: | String 
 | 
| Defined in: | test/helpers/test_puma/response.rb | 
Overview
A subclass of String, allows processing the response returned by PumaSocket#send_http_read_response and the read_response method added to native socket instances (created with PumaSocket#new_socket and PumaSocket#send_http.
Instance Attribute Summary
- #times rw
Instance Method Summary
- #body
- 
    
      #decode_body  ⇒ String 
    
    Decodes a chunked body. 
- 
    
      #headers  ⇒ Array<String> 
    
    Returns response headers as an array of lines. 
- 
    
      #headers_hash  ⇒ Hash 
    
    Returns response headers as a hash. 
- #status
Instance Attribute Details
#times (rw)
[ GitHub ]# File 'test/helpers/test_puma/response.rb', line 12
attr_accessor :times
Instance Method Details
#body
[ GitHub ]# File 'test/helpers/test_puma/response.rb', line 35
def body self.split(RESP_SPLIT, 2).last end
    #decode_body  ⇒ String 
  
Decodes a chunked body
# File 'test/helpers/test_puma/response.rb', line 41
def decode_body decoded = String.new # rubocop: disable Performance/UnfreezeString body = self.split(RESP_SPLIT, 2).last body = body.byteslice 0, body.bytesize - 5 # remove terminating bytes loop do size, body = body.split LINE_SPLIT, 2 size = size.to_i 16 decoded << body.byteslice(0, size) body = body.byteslice (size+2)..-1 # remove segment ending "\r\n" break if body.empty? || body.nil? end decoded end
    #headers  ⇒ Array<String> 
  
Returns response headers as an array of lines
# File 'test/helpers/test_puma/response.rb', line 16
def headers @headers ||= begin ary = self.split(RESP_SPLIT, 2).first.split LINE_SPLIT @status = ary.shift ary end end
    #headers_hash  ⇒ Hash 
  
Returns response headers as a hash. All keys and values are strings.
# File 'test/helpers/test_puma/response.rb', line 26
def headers_hash @headers_hash ||= headers.map { |hdr| hdr.split ': ', 2 }.to_h end
#status
[ GitHub ]# File 'test/helpers/test_puma/response.rb', line 30
def status headers @status end