Class: K8::RackResponse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRackResponse

Returns a new instance of RackResponse.



1574
1575
1576
1577
1578
# File 'lib/keight.rb', line 1574

def initialize
  #; [!ehdkl] default status code is 200.
  @status_code = 200
  @headers = {}
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



1581
1582
1583
# File 'lib/keight.rb', line 1581

def headers
  @headers
end

#status_codeObject Also known as: status

Returns the value of attribute status_code.



1580
1581
1582
# File 'lib/keight.rb', line 1580

def status_code
  @status_code
end

Instance Method Details

#clearObject



1628
1629
# File 'lib/keight.rb', line 1628

def clear
end

#content_lengthObject



1599
1600
1601
1602
# File 'lib/keight.rb', line 1599

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

#content_length=(length) ⇒ Object



1604
1605
1606
# File 'lib/keight.rb', line 1604

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

#content_typeObject



1591
1592
1593
# File 'lib/keight.rb', line 1591

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

#content_type=(content_type) ⇒ Object



1595
1596
1597
# File 'lib/keight.rb', line 1595

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


1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
# File 'lib/keight.rb', line 1608

def set_cookie(name, value, domain: nil, path: nil, expires: nil, max_age: nil, httponly: nil, secure: nil)
  #; [!oanme] converts Time object into HTTP timestamp string.
  if expires && expires.is_a?(Time)
    expires = Util.http_utc_time(expires)
  end
  #; [!58tby] adds 'Set-Cookie' response header.
  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
  #; [!u9w9l] supports multiple cookies.
  value = @headers['Set-Cookie']
  @headers['Set-Cookie'] = value ? (value << "\n" << s) : s
  #; [!7otip] returns cookie string.
  return s
end

#status_lineObject



1586
1587
1588
1589
# File 'lib/keight.rb', line 1586

def status_line
  #; [!apy81] returns status line such as '200 OK'.
  return "#{@status_code} #{HTTP_RESPONSE_STATUS[@status_code] || 'UNKNOWN'}"
end