Created
June 28, 2013 14:49
-
-
Save claudijd/5885259 to your computer and use it in GitHub Desktop.
Monkey Patched handsoap http_client_driver implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'handsoap/http/drivers/abstract_driver' | |
module Handsoap | |
module Http | |
module Drivers | |
class HttpClientDriver < AbstractDriver | |
def self.load! | |
require 'httpclient' | |
end | |
def send_http_request(request) | |
http_client = HTTPClient.new | |
#START MONKEY PATCH | |
http_client.ssl_config.clear_cert_store | |
http_client.ssl_config.cert_store.set_default_paths | |
#END MONKEY PATCH | |
# Set credentials. The driver will negotiate the actual scheme | |
if request.username && request.password | |
domain = request.url.match(/^(http(s?):\/\/[^\/]+\/)/)[1] | |
http_client.set_auth(domain, request.username, request.password) | |
end | |
http_client.ssl_config.set_trust_ca(request.trust_ca_file) if request.trust_ca_file | |
http_client.ssl_config.set_client_cert_file(request.client_cert_file,request.client_cert_key_file) if request.client_cert_file and request.client_cert_key_file | |
#http_client.ssl_config.verify_mode = request.ssl_verify_mode if request.ssl_verify_mode | |
# pack headers | |
headers = request.headers.inject([]) do |arr, (k,v)| | |
arr + v.map {|x| [k,x] } | |
end | |
response = http_client.request(request.http_method, request.url, nil, request.body, headers) | |
response_headers = response.header.all.inject({}) do |h, (k, v)| | |
k.downcase! | |
if h[k].nil? | |
h[k] = [v] | |
else | |
h[k] << v | |
end | |
h | |
end | |
parse_http_part(response_headers, response.content, response.status, response.contenttype) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment