Skip to content

Commit b8bfd1f

Browse files
committed
Add user-agent
1 parent 89821cd commit b8bfd1f

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

lib/code_climate/test_reporter/client.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module TestReporter
88
class Client
99

1010
DEFAULT_TIMEOUT = 5 # in seconds
11+
USER_AGENT = "Code Climate (Ruby Test Reporter v#{VERSION})"
1112

1213
def host
1314
ENV["CODECLIMATE_API_HOST"] ||
@@ -33,6 +34,7 @@ def batch_post_results(files)
3334
end
3435
post_body << "\r\n--#{boundary}--\r\n"
3536
request = Net::HTTP::Post.new(uri.request_uri)
37+
request["User-Agent"] = USER_AGENT
3638
request.body = post_body.join
3739
request["Content-Type"] = "multipart/form-data, boundary=#{boundary}"
3840
response = http.request(request)
@@ -49,6 +51,7 @@ def post_results(result)
4951
http = http_client(uri)
5052

5153
request = Net::HTTP::Post.new(uri.path)
54+
request["User-Agent"] = USER_AGENT
5255
request["Content-Type"] = "application/json"
5356
request["Content-Encoding"] = "gzip"
5457
request.body = compress(result.to_json)

spec/lib/formatter_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ module CodeClimate::TestReporter
9595
app.http_content_encoding.should == "gzip"
9696
uncompressed = inflate(app.request_body)
9797
JSON.parse(uncompressed).should == expected_request
98+
app.http_user_agent.should include("v#{CodeClimate::TestReporter::VERSION}")
9899
end
99100
end
100101
end

spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def content_type
3737
def http_content_encoding
3838
@env["HTTP_CONTENT_ENCODING"]
3939
end
40+
41+
def http_user_agent
42+
@env["HTTP_USER_AGENT"]
43+
end
4044
end
4145

4246

0 commit comments

Comments
 (0)