Class: Sumologic::Http::CookieJar

Inherits:
Object
  • Object
show all
Defined in:
lib/sumologic/http/cookie_jar.rb

Overview

Simple cookie jar for storing and managing HTTP cookies Handles Set-Cookie response headers and Cookie request headers

Instance Method Summary collapse

Constructor Details

#initializeCookieJar



8
9
10
# File 'lib/sumologic/http/cookie_jar.rb', line 8

def initialize
  @cookies = {}
end

Instance Method Details

#any?Boolean

Check if any cookies are stored



30
31
32
# File 'lib/sumologic/http/cookie_jar.rb', line 30

def any?
  @cookies.any?
end

#clearObject

Clear all stored cookies



35
36
37
# File 'lib/sumologic/http/cookie_jar.rb', line 35

def clear
  @cookies.clear
end

#store_from_response(response) ⇒ Object

Store cookies from response Set-Cookie headers



13
14
15
16
17
18
19
# File 'lib/sumologic/http/cookie_jar.rb', line 13

def store_from_response(response)
  return unless response['Set-Cookie']

  Array(response['Set-Cookie']).each do |cookie_header|
    parse_and_store(cookie_header)
  end
end

#to_headerObject

Format cookies for Cookie request header Returns nil if no cookies stored



23
24
25
26
27
# File 'lib/sumologic/http/cookie_jar.rb', line 23

def to_header
  return nil if @cookies.empty?

  @cookies.map { |name, value| "#{name}=#{value}" }.join('; ')
end