Sha256: df41faa172d5b94635aa91d3deb7385b8abbe1a00fa7e038958b1709b80cd39c

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

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

module Handsoap
  module Http
    module Drivers
      class CurbDriver < AbstractDriver
        attr_accessor :enable_cookies

        def initialize
          @enable_cookies = false
        end

        def self.load!
          require 'curb'
        end

        def get_curl(url)
          if @curl
            @curl.url = url
          else
            @curl = ::Curl::Easy.new(url)
            @curl.enable_cookies = @enable_cookies
          end
          @curl
        end
        private :get_curl

        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
          # 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

2 entries across 2 versions & 1 rubygems

Version Path
handsoap-1.1.2 lib/handsoap/http/drivers/curb_driver.rb
handsoap-1.1.1 lib/handsoap/http/drivers/curb_driver.rb