Sha256: 62172fd8ba0d337848fb50040a336f8c1782fe98ddc025c31ddbc0d026d46433

Contents?: true

Size: 1.91 KB

Versions: 8

Compression:

Stored size: 1.91 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.timeout         = Handsoap.timeout
            @curl.enable_cookies  = @enable_cookies
            
            if Handsoap.follow_redirects?
              @curl.follow_location = true
              @curl.max_redirects   = Handsoap.max_redirects
            end
          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

8 entries across 8 versions & 3 rubygems

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