Skip to content

Commit 429af62

Browse files
Steven Hazelp0deje
authored andcommitted
Add a User-Agent header for Ruby HTTP requests.
Signed-off-by: Alex Rodionov <p0deje@gmail.com>
1 parent a433820 commit 429af62

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

rb/lib/selenium-webdriver.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616
# under the License.
1717

1818
require 'selenium/webdriver'
19+
20+
module Selenium
21+
VERSION = "3.11.0".freeze
22+
end

rb/lib/selenium/webdriver/remote/http/common.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class Common
2424
CONTENT_TYPE = 'application/json'.freeze
2525
DEFAULT_HEADERS = {
2626
'Accept' => CONTENT_TYPE,
27-
'Content-Type' => "#{CONTENT_TYPE}; charset=UTF-8"
27+
'Content-Type' => "#{CONTENT_TYPE}; charset=UTF-8",
28+
'User-Agent' => "selenium/#{Selenium::VERSION} (ruby #{Platform.os})"
2829
}.freeze
2930

3031
attr_accessor :timeout

rb/selenium-webdriver.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
root = File.expand_path(File.dirname(__FILE__))
22
raise "cwd must be #{root} when reading gemspec" if root != Dir.pwd
3+
require 'selenium'
34

45
Gem::Specification.new do |s|
56
s.name = 'selenium-webdriver'
6-
s.version = '3.11.0'
7+
s.version = Selenium::VERSION
78

89
s.authors = ['Alex Rodionov', 'Titus Fortner']
910
s.email = ['p0deje@gmail.com', 'titusfortner@gmail.com']

rb/spec/unit/selenium/webdriver/remote/http/common_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ module Http
3232

3333
common.call(:post, 'clear', nil)
3434
end
35+
36+
it 'sends a standard User-Agent by default' do
37+
common = Common.new
38+
common.server_url = URI.parse('http://server')
39+
40+
expect(common).to receive(:request)
41+
.with(:post, URI.parse('http://server/session'),
42+
hash_including(
43+
'User-Agent' =>
44+
a_string_matching(/^selenium\/#{Selenium::VERSION} \(ruby .*\)$/)),
45+
'{}')
46+
47+
common.call(:post, 'session', nil)
48+
end
3549
end
3650
end # Http
3751
end # Remote

0 commit comments

Comments
 (0)