Class: Chef::REST::RESTRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/rest/rest_request.rb

Constant Summary collapse

UA_COMMON =
"/#{::Chef::VERSION} (#{engine}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}; ohai-#{Ohai::VERSION}; #{RUBY_PLATFORM}; +http://opscode.com)"
DEFAULT_UA =
"Chef Client" << UA_COMMON

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, req_body, base_headers = {}) ⇒ RESTRequest

Returns a new instance of RESTRequest



57
58
59
60
61
62
63
64
# File 'lib/chef/rest/rest_request.rb', line 57

def initialize(method, url, req_body, base_headers={})
  @method, @url = method, url
  @request_body = nil
  @cookies = CookieJar.instance
  configure_http_client
  build_headers(base_headers)
  configure_http_request(req_body)
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers



55
56
57
# File 'lib/chef/rest/rest_request.rb', line 55

def headers
  @headers
end

#http_clientObject (readonly)

Returns the value of attribute http_client



55
56
57
# File 'lib/chef/rest/rest_request.rb', line 55

def http_client
  @http_client
end

#http_requestObject (readonly)

Returns the value of attribute http_request



55
56
57
# File 'lib/chef/rest/rest_request.rb', line 55

def http_request
  @http_request
end

#methodObject (readonly)

Returns the value of attribute method



55
56
57
# File 'lib/chef/rest/rest_request.rb', line 55

def method
  @method
end

#urlObject (readonly)

Returns the value of attribute url



55
56
57
# File 'lib/chef/rest/rest_request.rb', line 55

def url
  @url
end

Class Method Details

.user_agentObject



51
52
53
# File 'lib/chef/rest/rest_request.rb', line 51

def self.user_agent
  @user_agent ||= DEFAULT_UA
end

.user_agent=(ua) ⇒ Object



47
48
49
# File 'lib/chef/rest/rest_request.rb', line 47

def self.user_agent=(ua)
  @user_agent = ua
end

Instance Method Details

#callObject



82
83
84
85
86
87
88
89
90
# File 'lib/chef/rest/rest_request.rb', line 82

def call
  hide_net_http_bug do
    http_client.request(http_request) do |response|
      store_cookie(response)
      yield response if block_given?
      response
    end
  end
end

#configObject



92
93
94
# File 'lib/chef/rest/rest_request.rb', line 92

def config
  Chef::Config
end

#hostObject



66
67
68
# File 'lib/chef/rest/rest_request.rb', line 66

def host
  @url.host
end

#pathObject



78
79
80
# File 'lib/chef/rest/rest_request.rb', line 78

def path
  @url.path.empty? ? "/" : @url.path
end

#portObject



70
71
72
# File 'lib/chef/rest/rest_request.rb', line 70

def port
  @url.port
end

#queryObject



74
75
76
# File 'lib/chef/rest/rest_request.rb', line 74

def query
  @url.query
end