Class: K8::Response
- Inherits:
-
Object
- Object
- K8::Response
- Defined in:
- lib/keight.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status_code ⇒ Object
(also: #status)
Returns the value of attribute status_code.
Instance Method Summary collapse
- #clear ⇒ Object
- #content_length ⇒ Object
- #content_length=(length) ⇒ Object
- #content_type ⇒ Object
- #content_type=(content_type) ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #set_cookie(name, value, domain: nil, path: nil, expires: nil, max_age: nil, httponly: nil, secure: nil) ⇒ Object
Constructor Details
#initialize ⇒ Response
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
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
669 670 671 |
# File 'lib/keight.rb', line 669 def headers @headers end |
#status_code ⇒ Object 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
#clear ⇒ Object
704 705 |
# File 'lib/keight.rb', line 704 def clear end |
#content_length ⇒ Object
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_type ⇒ Object
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 |
#set_cookie(name, value, domain: nil, path: nil, expires: nil, max_age: nil, httponly: nil, secure: nil) ⇒ Object
691 692 693 694 695 696 697 698 699 700 701 702 |
# File 'lib/keight.rb', line 691 def (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 |