Sha256: 320811a8fd97494ff4ef268ba4b796c04e2e483034b4345dfa8ec75626569409

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require "net/http"

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 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 = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)

            retried = false
            begin
              response = http.request(request, payload)
            rescue Errno::ECONNABORTED, Errno::ECONNRESET
              # this happens sometimes on windows?!
              raise if retried
              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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
selenium-webdriver-0.0.22 remote/client/src/rb/lib/selenium/webdriver/remote/http/default.rb