Class: Chef::HTTP::CookieManager

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/http/cookie_manager.rb

Overview

An HTTP middleware to manage storing/sending cookies in HTTP requests. Most HTTP communication in Chef does not need cookies, it was originally implemented to support OpenID, but it's not known who might be relying on it, so it's included with Chef::REST

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CookieManager

Returns a new instance of CookieManager


30
31
32
# File 'lib/chef/http/cookie_manager.rb', line 30

def initialize(options = {})
  @cookies = CookieJar.instance
end

Instance Method Details

#handle_request(method, url, headers = {}, data = false) ⇒ Object


34
35
36
37
38
39
40
# File 'lib/chef/http/cookie_manager.rb', line 34

def handle_request(method, url, headers = {}, data = false)
  @host, @port = url.host, url.port
  if @cookies.has_key?("#{@host}:#{@port}")
    headers["Cookie"] = @cookies["#{@host}:#{@port}"]
  end
  [method, url, headers, data]
end

#handle_response(http_response, rest_request, return_value) ⇒ Object


42
43
44
45
46
47
# File 'lib/chef/http/cookie_manager.rb', line 42

def handle_response(http_response, rest_request, return_value)
  if http_response["set-cookie"]
    @cookies["#{@host}:#{@port}"] = http_response["set-cookie"]
  end
  [http_response, rest_request, return_value]
end

#handle_stream_complete(http_response, rest_request, return_value) ⇒ Object


53
54
55
# File 'lib/chef/http/cookie_manager.rb', line 53

def handle_stream_complete(http_response, rest_request, return_value)
  [http_response, rest_request, return_value]
end

#stream_response_handler(response) ⇒ Object


49
50
51
# File 'lib/chef/http/cookie_manager.rb', line 49

def stream_response_handler(response)
  nil
end