Sha256: 55b209e2d8a477d86f407e72e0cd2f60d34a69abe65b6f5b8cb1332e1f31a898

Contents?: true

Size: 1.76 KB

Versions: 4

Compression:

Stored size: 1.76 KB

Contents

require "net/https"

module Selenium
  module WebDriver
    module Remote
      module Http
        # @private
        class Default < Common

          private

          def http
            # ignoring SSL for now
            @http ||= (
              http = Net::HTTP.new @server_url.host, @server_url.port
              if @server_url.scheme == "https"
                http.use_ssl = true
                http.verify_mode = OpenSSL::SSL::VERIFY_NONE
              end

              if self.class.timeout
                http.connect_timeout = self.class.timeout
                http.read_timeout    = self.class.timeout
              end

              http
            )
          end

          def request(verb, url, headers, payload, redirects = 0)
            request = new_request_for(verb, url, headers)

            retried = false
            begin
              response = http.request(request, payload)
            rescue Errno::ECONNABORTED, Errno::ECONNRESET
              # this happens sometimes on windows?!
              raise if retried

              request = new_request_for(verb, url, headers)
              retried = true

              retry
            end

            if response.kind_of? Net::HTTPRedirection
              raise Error::WebDriverError, "too many redirects" if redirects >= MAX_REDIRECTS
              request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)
            else
              create_response response.code, response.body, response.content_type
            end
          end

          def new_request_for(verb, url, headers)
            Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)
          end

        end # Default
      end # Http
    end # Remote
  end # WebDriver
end # Selenium

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
selenium-webdriver-0.0.28 lib/selenium/webdriver/remote/http/default.rb
selenium-webdriver-0.0.27 lib/selenium/webdriver/remote/http/default.rb
selenium-webdriver-0.0.26 lib/selenium/webdriver/remote/http/default.rb
selenium-webdriver-0.0.25 lib/selenium/webdriver/remote/http/default.rb