Sha256: d8f79a57aa1f366f33f369c1df93e8ca25e6b34c69d8ef7cd2ac00f6debed232

Contents?: true

Size: 1.55 KB

Versions: 6

Compression:

Stored size: 1.55 KB

Contents

require 'typhoeus'

module Selenium
module WebDriver
module Remote

module Http

# The default client is unusably slow on platforms where Ruby IO is lacking in
# performance, like Windows.
class Typhoeus < Common

    private

    def request( verb, url, headers, payload )
        url = url.to_s

        headers.delete 'Content-Length'

        options = {
            headers:        headers,
            maxredirs:      MAX_REDIRECTS,
            followlocation: true,
            # Small trick to cancel out http_proxy env variables which would
            # otherwise be honoured by libcurl and hinder browser communications.
            proxy:          ''
        }

        options[:timeout] = @timeout if @timeout

        case verb
            when :post, :put
                options[:body] = payload.to_s

            when :get, :delete, :head
            else
                raise Error::WebDriverError, "Unknown HTTP verb: #{verb.inspect}"
        end

        response = ::Typhoeus::Request.send( verb, url, options )

        create_response extract_real_code( response ), response.body,
                        response.headers['Content-Type']
    end

    def extract_real_code( response )
        # Typhoeus sometimes gets confused when running under JRuby from multiple
        # threads:
        #  https://github.com/typhoeus/typhoeus/issues/411
        if Arachni.jruby?
            code = response.response_headers.match( /HTTP\/1\.\d\s(\d+)\s/ )[1] || 0
            code.to_i
        else
            response.code
        end
    end

end

end
end
end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
arachni-1.3.2 lib/arachni/selenium/webdriver/remote/http/typhoeus.rb
arachni-1.3.1 lib/arachni/selenium/webdriver/remote/http/typhoeus.rb
arachni-1.3 lib/arachni/selenium/webdriver/remote/http/typhoeus.rb
arachni-1.2.1 lib/arachni/selenium/webdriver/remote/http/typhoeus.rb
arachni-1.2 lib/arachni/selenium/webdriver/remote/http/typhoeus.rb
arachni-1.1 lib/arachni/selenium/webdriver/remote/http/typhoeus.rb