Skip to content

Commit

Permalink
Add a User-Agent header for Ruby HTTP requests.
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Rodionov <p0deje@gmail.com>
  • Loading branch information
Steven Hazel authored and p0deje committed Mar 28, 2018
1 parent a433820 commit 429af62
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions rb/lib/selenium-webdriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
# under the License.

require 'selenium/webdriver'

module Selenium
VERSION = "3.11.0".freeze
end
3 changes: 2 additions & 1 deletion rb/lib/selenium/webdriver/remote/http/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Common
CONTENT_TYPE = 'application/json'.freeze
DEFAULT_HEADERS = {
'Accept' => CONTENT_TYPE,
'Content-Type' => "#{CONTENT_TYPE}; charset=UTF-8"
'Content-Type' => "#{CONTENT_TYPE}; charset=UTF-8",
'User-Agent' => "selenium/#{Selenium::VERSION} (ruby #{Platform.os})"
}.freeze

attr_accessor :timeout
Expand Down
3 changes: 2 additions & 1 deletion rb/selenium-webdriver.gemspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
root = File.expand_path(File.dirname(__FILE__))
raise "cwd must be #{root} when reading gemspec" if root != Dir.pwd
require 'selenium'

Gem::Specification.new do |s|
s.name = 'selenium-webdriver'
s.version = '3.11.0'
s.version = Selenium::VERSION

s.authors = ['Alex Rodionov', 'Titus Fortner']
s.email = ['p0deje@gmail.com', 'titusfortner@gmail.com']
Expand Down
14 changes: 14 additions & 0 deletions rb/spec/unit/selenium/webdriver/remote/http/common_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ module Http

common.call(:post, 'clear', nil)
end

it 'sends a standard User-Agent by default' do
common = Common.new
common.server_url = URI.parse('http://server')

expect(common).to receive(:request)
.with(:post, URI.parse('http://server/session'),
hash_including(
'User-Agent' =>
a_string_matching(/^selenium\/#{Selenium::VERSION} \(ruby .*\)$/)),
'{}')

common.call(:post, 'session', nil)
end
end
end # Http
end # Remote
Expand Down

0 comments on commit 429af62

Please sign in to comment.