Path: blob/trunk/rb/lib/selenium/webdriver/remote/http/curb.rb
1990 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require 'curb'2021module Selenium22module WebDriver23module Remote24module Http25#26# An alternative to the default Net::HTTP client.27#28# This can be used for the Firefox and Remote drivers if you have Curb29# installed.30#31# @example Using Curb32# require 'selenium/webdriver/remote/http/curb'33# include Selenium34#35# driver = WebDriver.for :firefox, :http_client => WebDriver::Remote::Http::Curb.new36#3738class Curb < Common39attr_accessor :timeout4041def initialize(timeout: nil)42@timeout = timeout43super()44end4546def quit_errors47[Curl::Err::RecvError] + super48end4950private5152def request(verb, url, headers, payload)53client.url = url.to_s5455# workaround for http://github.com/taf2/curb/issues/issue/4056# curb will handle this for us anyway57headers.delete 'Content-Length'5859client.headers = headers6061# http://github.com/taf2/curb/issues/issue/3362client.head = false63client.delete = false6465case verb66when :get67client.http_get68when :post69client.post_body = payload || ''70client.http_post71when :put72client.put_data = payload || ''73client.http_put74when :delete75client.http_delete76when :head77client.http_head78else79raise Error::WebDriverError, "unknown HTTP verb: #{verb.inspect}"80end8182create_response client.response_code, client.body_str, client.content_type83end8485def client86@client ||= begin87c = Curl::Easy.new8889c.max_redirects = MAX_REDIRECTS90c.follow_location = true91c.timeout = timeout if timeout92c.verbose = WebDriver.logger.debug?93c94end95end96end # Curb97end # Http98end # Remote99end # WebDriver100end # Selenium101102103