Sha256: 7fde498d43abf2a4bf50cf016c16e353589138be9b0d7131f13021807730be9a

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

# -*- coding: utf-8 -*-
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
          # 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
          # 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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
handsoap-1.1.8 lib/handsoap/http/drivers/http_client_driver.rb
handsoap-1.1.7 lib/handsoap/http/drivers/http_client_driver.rb
pgericson-handsoap-1.1.10 lib/handsoap/http/drivers/http_client_driver.rb
pgericson-handsoap-1.1.9 lib/handsoap/http/drivers/http_client_driver.rb
pgericson-handsoap-1.1.8 lib/handsoap/http/drivers/http_client_driver.rb
pgericson-handsoap-1.1.7 lib/handsoap/http/drivers/http_client_driver.rb
handsoap-1.1.6 lib/handsoap/http/drivers/http_client_driver.rb
handsoap-1.1.5 lib/handsoap/http/drivers/http_client_driver.rb