def execute(request, uri, parameters = {}, headers = {})
{
'content-type' => 'application/x-www-form-urlencoded'
}.merge(headers).each { |k,v| request[k] = v }
@cookie_manager[uri].each { |k,v|
request['Cookie'] = v.to_s
} if @cookie_manager[uri]
http = agent_class.new( uri.host, uri.port )
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
request_data = case request['Content-Type']
when /boundary=(.*)$/
boundary_data_for($1, parameters)
else
query_string_for(parameters)
end
request['Content-Length'] = request_data.length.to_s
response = http.request(request, request_data)
(response.get_fields('Set-Cookie') || []).each do |raw_cookie|
WEBrick::Cookie.parse_set_cookies(raw_cookie).each { |baked_cookie|
baked_cookie.domain ||= url.host
baked_cookie.path ||= url.path
@cookie_manager.add(uri, baked_cookie)
}
end
return response.body if response.class <= Net::HTTPSuccess
if response.class <= Net::HTTPRedirection
location = response['Location']
unless location =~ /^http/
location = "#{uri.scheme}://#{uri.host}#{location}"
end
uri = URI.parse(location)
execute(agent_class::Get.new(uri.request_uri), uri)
end
end