Class: K8::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/keight.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



663
664
665
666
# File 'lib/keight.rb', line 663

def initialize
  @status_code = 200
  @headers = {}
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



669
670
671
# File 'lib/keight.rb', line 669

def headers
  @headers
end

#status_codeObject Also known as: status

Returns the value of attribute status_code.



668
669
670
# File 'lib/keight.rb', line 668

def status_code
  @status_code
end

Instance Method Details

#clearObject



704
705
# File 'lib/keight.rb', line 704

def clear
end

#content_lengthObject



682
683
684
685
# File 'lib/keight.rb', line 682

def content_length
  s = @headers['Content-Length']
  return s ? s.to_i : nil
end

#content_length=(length) ⇒ Object



687
688
689
# File 'lib/keight.rb', line 687

def content_length=(length)
  @headers['Content-Length'] = length.to_s
end

#content_typeObject



674
675
676
# File 'lib/keight.rb', line 674

def content_type
  return @headers['Content-Type']
end

#content_type=(content_type) ⇒ Object



678
679
680
# File 'lib/keight.rb', line 678

def content_type=(content_type)
  @headers['Content-Type'] = content_type
end


691
692
693
694
695
696
697
698
699
700
701
702
# File 'lib/keight.rb', line 691

def set_cookie(name, value, domain: nil, path: nil, expires: nil, max_age: nil, httponly: nil, secure: nil)
  s = "#{name}=#{value}"
  s << "; Domain=#{domain}"   if domain
  s << "; Path=#{path}"       if path
  s << "; Expires=#{expires}" if expires
  s << "; Max-Age=#{max_age}" if max_age
  s << "; HttpOnly"           if httponly
  s << "; Secure"             if secure
  value = @headers['Set-Cookie']
  @headers['Set-Cookie'] = value ? (value << "\n" << s) : s
  return value
end