summaryrefslogtreecommitdiff
path: root/lib/chef/http.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-10-07 16:40:04 -0700
committerdanielsdeleo <dan@opscode.com>2013-10-08 15:01:48 -0700
commit75a71fcdb1e03ba405fe0ddf1d9717e4a5c57b03 (patch)
treed36696d88b997580dc13d24856ecfde3a5cbd29c /lib/chef/http.rb
parent4ba34085703951587586aa68f616087a9a95cb69 (diff)
downloadchef-75a71fcdb1e03ba405fe0ddf1d9717e4a5c57b03.tar.gz
Refactor HTTP streaming to reuse base implementations
Diffstat (limited to 'lib/chef/http.rb')
-rw-r--r--lib/chef/http.rb15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index 98070e097b..94d9d4d145 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -155,17 +155,20 @@ class Chef
end
def http_client
- @http_client ||= BasicClient.new(create_url(url))
+ BasicClient.new(create_url(url))
end
# Runs a synchronous HTTP request, with no middleware applied (use #request
# to have the middleware applied). The entire response will be loaded into memory.
- def send_http_request(method, url, headers, body)
+ def send_http_request(method, url, headers, body, &response_handler)
headers = build_headers(method, url, headers, body)
retrying_http_errors(url) do
-
- request, response = http_client.request(method, url, body, headers) {|r| r.read_body }
+ if block_given?
+ request, response = http_client.request(method, url, body, headers, &response_handler)
+ else
+ request, response = http_client.request(method, url, body, headers) {|r| r.read_body }
+ end
@last_response = response
Chef::Log.debug("---- HTTP Status and Header Data: ----")
@@ -182,7 +185,9 @@ class Chef
[response, request, false]
elsif redirect_location = redirected_to(response)
if [:GET, :HEAD].include?(method)
- follow_redirect {api_request(method, create_url(redirect_location))}
+ follow_redirect do
+ send_http_request(method, create_url(redirect_location), headers, body, &response_handler)
+ end
else
raise Exceptions::InvalidRedirect, "#{method} request was redirected from #{url} to #{redirect_location}. Only GET and HEAD support redirects."
end