Sha256: 4c8c6e64bf5b9f11e98390793141c4232d3619fb1edbb57d5ee9804dee20e6f4

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# -*- coding: utf-8 -*-
require 'handsoap/http/drivers/abstract_driver'

module Handsoap
  module Http
    module Drivers
      class CurbDriver < AbstractDriver
        def self.load!
          require 'curb'
        end

        def send_http_request(request)
          http_client = Curl::Easy.new(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
          # 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
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
handsoap-1.1.0 lib/handsoap/http/drivers/curb_driver.rb