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
USER_AGENT =
"User-Agent".freeze
ACCEPT_ENCODING =
"Accept-Encoding".freeze
ENCODING_GZIP_DEFLATE =
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3".freeze
GET =
"get".freeze
PUT =
"put".freeze
POST =
"post".freeze
DELETE =
"delete".freeze
HEAD =
"head".freeze
HTTPS =
"https".freeze
SLASH =
"/".freeze

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.



72
73
74
75
76
77
78
79
# File 'lib/chef/rest/rest_request.rb', line 72

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.



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

def headers
  @headers
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



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

def http_client
  @http_client
end

#http_requestObject (readonly)

Returns the value of attribute http_request.



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

def http_request
  @http_request
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.user_agentObject



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

def self.user_agent
  @user_agent ||= DEFAULT_UA
end

.user_agent=(ua) ⇒ Object



62
63
64
# File 'lib/chef/rest/rest_request.rb', line 62

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

Instance Method Details

#callObject



97
98
99
100
101
102
103
104
105
# File 'lib/chef/rest/rest_request.rb', line 97

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



107
108
109
# File 'lib/chef/rest/rest_request.rb', line 107

def config
  Chef::Config
end

#hostObject



81
82
83
# File 'lib/chef/rest/rest_request.rb', line 81

def host
  @url.host
end

#pathObject



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

def path
  @url.path.empty? ? SLASH : @url.path
end

#portObject



85
86
87
# File 'lib/chef/rest/rest_request.rb', line 85

def port
  @url.port
end

#queryObject



89
90
91
# File 'lib/chef/rest/rest_request.rb', line 89

def query
  @url.query
end