Class: Handsoap::Http::Drivers::HttpClientDriver

Inherits:
AbstractDriver show all
Defined in:
lib/handsoap/http/drivers/http_client_driver.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from AbstractDriver

#initialize, #parse_headers, #parse_http_part, #parse_multipart, #parse_multipart_boundary

Constructor Details

This class inherits a constructor from Handsoap::Http::Drivers::AbstractDriver

Class Method Details

+ (Object) load!



8
9
10
# File 'lib/handsoap/http/drivers/http_client_driver.rb', line 8

def self.load!
  require 'httpclient'
end

Instance Method Details

- (Object) send_http_request(request)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/handsoap/http/drivers/http_client_driver.rb', line 12

def send_http_request(request)
  http_client = HTTPClient.new
  # 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