Class: Handsoap::Http::Drivers::CurbDriver

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractDriver

#parse_headers, #parse_http_part, #parse_multipart, #parse_multipart_boundary

Constructor Details

#initializeCurbDriver

Returns a new instance of CurbDriver.



10
11
12
# File 'lib/handsoap/http/drivers/curb_driver.rb', line 10

def initialize
  @enable_cookies = false
end

Instance Attribute Details

#enable_cookiesObject

Returns the value of attribute enable_cookies.



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

def enable_cookies
  @enable_cookies
end

Class Method Details

.load!Object



14
15
16
# File 'lib/handsoap/http/drivers/curb_driver.rb', line 14

def self.load!
  require 'curb'
end

Instance Method Details

#send_http_request(request) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/handsoap/http/drivers/curb_driver.rb', line 36

def send_http_request(request)
  http_client = get_curl(request.url)
  # Set credentials. The driver will negotiate the actual scheme
  if request.username && request.password
    http_client.userpwd = [request.username, ":", request.password].join
  end
  http_client.cacert = request.trust_ca_file if request.trust_ca_file
  http_client.cert = request.client_cert_file if request.client_cert_file
  # I have submitted a patch for this to curb, but it's not yet supported. If you get errors, try upgrading curb.
  http_client.cert_key = request.client_cert_key_file if request.client_cert_key_file
  # pack headers
  headers = request.headers.inject([]) do |arr, (k,v)|
    arr + v.map {|x| "#{k}: #{x}" }
  end
  http_client.headers = headers
  # I don't think put/delete is actually supported ..
  case request.http_method
  when :get
    http_client.http_get
  when :post
    http_client.http_post(request.body)
  when :put
    http_client.http_put(request.body)
  when :delete
    http_client.http_delete
  else
    raise "Unsupported request method #{request.http_method}"
  end
  parse_http_part(http_client.header_str.gsub(/^HTTP.*\r\n/, ""), http_client.body_str, http_client.response_code, http_client.content_type)
end