Module: Handsoap::Http::Curb

Defined in:
lib/handsoap/http.rb

Overview

driver for curb

Class Method Summary collapse

Class Method Details

.load!Object



160
161
162
# File 'lib/handsoap/http.rb', line 160

def self.load!
  require 'curb'
end

.send_http_request(request) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/handsoap/http.rb', line 163

def self.send_http_request(request)
  self.load!
  http_client = Curl::Easy.new(request.url)
  # 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
  Handsoap::Http.parse_http_part(http_client.header_str.gsub(/^HTTP.*\r\n/, ""), http_client.body_str, http_client.response_code, http_client.content_type)
end