This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Send user agents with all our tools #1289
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,26 @@ TEST(PostTest, put_performed) { | |
EXPECT_EQ(json["data"]["key"].asString(), "val"); | ||
} | ||
|
||
TEST(HttpClient, user_agent) { | ||
{ | ||
// test the default, when setUserAgent hasn't been called yet | ||
HttpClient http; | ||
|
||
const auto resp = http.get(server + "/user_agent", HttpInterface::kNoLimit); | ||
const auto app = resp.body.substr(0, resp.body.find('/')); | ||
EXPECT_EQ(app, "Aktualizr"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you provide a brief comment to make it clear that you're testing the expected default here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! |
||
} | ||
|
||
Utils::setUserAgent("blah"); | ||
|
||
{ | ||
HttpClient http; | ||
|
||
auto resp = http.get(server + "/user_agent", HttpInterface::kNoLimit); | ||
EXPECT_EQ(resp.body, "blah"); | ||
} | ||
} | ||
|
||
// TODO: add tests for HttpClient::download | ||
|
||
#ifndef __NO_MAIN__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,19 +55,17 @@ void TestUtils::writePathToConfig(const boost::filesystem::path &toml_in, const | |
} | ||
|
||
void TestUtils::waitForServer(const std::string &address) { | ||
CURL *handle = curl_easy_init(); | ||
if (handle == nullptr) { | ||
throw std::runtime_error("Could not initialize curl handle"); | ||
} | ||
curlEasySetoptWrapper(handle, CURLOPT_URL, address.c_str()); | ||
curlEasySetoptWrapper(handle, CURLOPT_CONNECTTIMEOUT, 3L); | ||
curlEasySetoptWrapper(handle, CURLOPT_NOBODY, 1L); | ||
curlEasySetoptWrapper(handle, CURLOPT_VERBOSE, 1L); | ||
curlEasySetoptWrapper(handle, CURLOPT_SSL_VERIFYPEER, 0L); | ||
CurlEasyWrapper curl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
|
||
curlEasySetoptWrapper(curl.get(), CURLOPT_URL, address.c_str()); | ||
curlEasySetoptWrapper(curl.get(), CURLOPT_CONNECTTIMEOUT, 3L); | ||
curlEasySetoptWrapper(curl.get(), CURLOPT_NOBODY, 1L); | ||
curlEasySetoptWrapper(curl.get(), CURLOPT_VERBOSE, 1L); | ||
curlEasySetoptWrapper(curl.get(), CURLOPT_SSL_VERIFYPEER, 0L); | ||
|
||
CURLcode result; | ||
for (size_t counter = 1; counter <= 100; counter++) { | ||
result = curl_easy_perform(handle); | ||
result = curl_easy_perform(curl.get()); | ||
if (result == 0) { | ||
// connection successful | ||
break; | ||
|
@@ -78,8 +76,6 @@ void TestUtils::waitForServer(const std::string &address) { | |
std::this_thread::sleep_for(std::chrono::milliseconds(200)); | ||
} | ||
|
||
curl_easy_cleanup(handle); | ||
|
||
if (result != 0) { | ||
throw std::runtime_error("Wait for server timed out"); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might override the user agent header specified by an HttpClient user/client in
extra_headers
.IMHO, statically predefined headers should be specified in a HTTP client factory configuration (which doesn't exist), so libaktualizr clients could specify desired mandatory headers in explicit way. Utils::set/getUserAgent() is an implicit API for libaktualizr clients/apps they need to be aware and set it before Aktualizr instantiation.
This is just my two cents and can be ignored since it will require more work :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree this is not especially elegant. The main problem I had is that different garage tools are using some common code that instantiates an HttpClient, that's why I opted for the less intrusive global setting.
I don't see much use case for HttpClient users redefining user agents dynamically though, it's maybe the (rare) kind of thing that can be setup globally.
But then I also question my choice of putting the API in utils.h. I'll try moving it to http client itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I understand that we need to be practical and balance between an ideal but time consuming and a just enough but quicker solutions.
BTW, at first glance, this PR, IMHO, is related to this one #1273 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol - i've been watching this PR to see how things went before pushing my change which will at best produce a merge conflict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha well... This PR is not really urgent anyway. Would you also prefer that to be done another way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. I was just wanted to see the approach that was chosen here since there's a good chance I could do the same thing in my change.