class Rack::MockResponse

def parse_cookies_from_header

def parse_cookies_from_header
  cookies = Hash.new
  set_cookie_header = headers['set-cookie']
  if set_cookie_header && !set_cookie_header.empty?
    Array(set_cookie_header).each do |cookie|
      cookie_name, cookie_filling = cookie.split('=', 2)
      cookie_attributes = identify_cookie_attributes cookie_filling
      parsed_cookie = Cookie.new(
        'name' => cookie_name.strip,
        'value' => cookie_attributes.fetch('value'),
        'path' => cookie_attributes.fetch('path', nil),
        'domain' => cookie_attributes.fetch('domain', nil),
        'expires' => cookie_attributes.fetch('expires', nil),
        'secure' => cookie_attributes.fetch('secure', false)
      )
      cookies.store(cookie_name, parsed_cookie)
    end
  end
  cookies
end