Class: Chef::HTTP::HTTPRequest

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

Constant Summary collapse

UA_COMMON =
"/#{::Chef::VERSION} (#{engine}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}; ohai-#{Ohai::VERSION}; #{RUBY_PLATFORM}; +https://chef.io)"
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
HOST_LOWER =
"host".freeze
URI_SCHEME_DEFAULT_PORT =
{ "http" => 80, "https" => 443 }.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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


75
76
77
78
79
80
# File 'lib/chef/http/http_request.rb', line 75

def initialize(method, url, req_body, base_headers = {})
  @method, @url = method, url
  @request_body = nil
  build_headers(base_headers)
  configure_http_request(req_body)
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers


73
74
75
# File 'lib/chef/http/http_request.rb', line 73

def headers
  @headers
end

#http_clientObject (readonly)

DEPRECATED. Call request on an HTTP client object instead.


117
118
119
# File 'lib/chef/http/http_request.rb', line 117

def http_client
  @http_client
end

#http_requestObject (readonly)

Returns the value of attribute http_request


73
74
75
# File 'lib/chef/http/http_request.rb', line 73

def http_request
  @http_request
end

#methodObject (readonly)

Returns the value of attribute method


73
74
75
# File 'lib/chef/http/http_request.rb', line 73

def method
  @method
end

#urlObject (readonly)

Returns the value of attribute url


73
74
75
# File 'lib/chef/http/http_request.rb', line 73

def url
  @url
end

Class Method Details

.user_agentObject


69
70
71
# File 'lib/chef/http/http_request.rb', line 69

def self.user_agent
  @user_agent ||= DEFAULT_UA
end

.user_agent=(ua) ⇒ Object


65
66
67
# File 'lib/chef/http/http_request.rb', line 65

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

Instance Method Details

#callObject

DEPRECATED. Call request on an HTTP client object instead.


103
104
105
106
107
108
109
110
# File 'lib/chef/http/http_request.rb', line 103

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

#configObject


112
113
114
# File 'lib/chef/http/http_request.rb', line 112

def config
  Chef::Config
end

#hostObject


82
83
84
# File 'lib/chef/http/http_request.rb', line 82

def host
  @url.hostname
end

#pathObject


98
99
100
# File 'lib/chef/http/http_request.rb', line 98

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

#portObject


90
91
92
# File 'lib/chef/http/http_request.rb', line 90

def port
  @url.port
end

#queryObject


94
95
96
# File 'lib/chef/http/http_request.rb', line 94

def query
  @url.query
end

#uri_safe_hostObject


86
87
88
# File 'lib/chef/http/http_request.rb', line 86

def uri_safe_host
  @url.host
end