Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http client add url support #833

Merged
merged 17 commits into from
Jun 11, 2021

Conversation

ohamuy
Copy link
Contributor

@ohamuy ohamuy commented Jun 7, 2021

HTTPClient : Support for full URL argument

Fixes # 812

Overloaded the CreateSession function allowing for url input:
Added it in the header file http_client.h
Implementation in http_client_curl.h
The function allows for url input instead of just host & port, utilizing the url parser in common folder. It returns an empty/non-existent host, and default port(80) if the parsing fails, and continues similarly to the original function otherwise.
One Unit test was changed to test the overloading function, but the overall functionality is not changed as the other original function parameters are tested in other unit tests. All tests passed, file builds successfully.
Lastly, the default port of 80 was removed from the original function because if the user ends up not providing a port, it will go through the other overloaded function and the url parser gives it a default port of 80

@lalitb @reyang

@ohamuy ohamuy requested a review from a team June 7, 2021 20:40
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 7, 2021

CLA Signed

The committers are authorized under a signed CLA.

@ThomsonTan
Copy link
Contributor

@ohamuy thanks for your contribution. Could you please fix the format?

@codecov
Copy link

codecov bot commented Jun 7, 2021

Codecov Report

Merging #833 (365e18d) into main (3741a8f) will decrease coverage by 0.02%.
The diff coverage is 92.31%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #833      +/-   ##
==========================================
- Coverage   95.50%   95.48%   -0.01%     
==========================================
  Files         156      156              
  Lines        6614     6614              
==========================================
- Hits         6316     6315       -1     
- Misses        298      299       +1     
Impacted Files Coverage Δ
...nclude/opentelemetry/ext/http/client/http_client.h 93.34% <ø> (ø)
...ntelemetry/ext/http/client/curl/http_client_curl.h 91.35% <85.72%> (-0.96%) ⬇️
ext/test/http/curl_http_test.cc 94.63% <100.00%> (ø)

@ohamuy
Copy link
Contributor Author

ohamuy commented Jun 7, 2021

@ThomsonTan Done! Also should I add to the change log for this commit?

@@ -227,8 +227,11 @@ class HttpClient
{
public:
virtual std::shared_ptr<Session> CreateSession(nostd::string_view host,
uint16_t port = 80) noexcept = 0;
virtual bool CancelAllSessions() noexcept = 0;
uint16_t port) noexcept = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the port parameter here, if the URL itself can contain scheme and port?
Should we rename the host parameter to url or uri ?

virtual bool CancelAllSessions() noexcept = 0;
uint16_t port) noexcept = 0;

virtual std::shared_ptr<Session> CreateSession(nostd::string_view url) noexcept = 0;
Copy link
Contributor

@maxgolov maxgolov Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see what you are doing. But I am not sure - maybe we should just deprecate the old method? I think this new one is much better. If we look at Javascript API for the open method, it only requires the URL parameter. In Java - this is also completely outsourced to java.net.URL . It's even more logical to assume that the session itself accepts URL object or string, rather than trying to implement multi-parameter parsing from host, port. Because it's rather [ scheme, host, port, location ] than simply [ host, port ] pair. It'd be best we just collapse all of it into single string parameter, then parse it using URL class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly, I just overloaded the function because that is what the @lalitb (the original issue creator) said might have been good. If its alright I can just simply remove the old parameter and just leave the new one since its also consistent with the GET and POST commands. But that is definitely a decision for the maintainers so when they give their input we can see whats the best course of action. @lalitb @reyang

Copy link
Member

@lalitb lalitb Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it makes sense to remove the original method as @maxgolov suggested.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the proposed changes are done. Thanks for the contribution.

@ohamuy
Copy link
Contributor Author

ohamuy commented Jun 9, 2021

@lalitb @maxgolov So I implemented the changes. Final change list:

-Deleted old CreateSession implementation
-Changed HTTPClient tests to match the correct parameters of the new function (all tests passed)
-Original constructor for Session was greatly simplified to one line as now we can pass in the scheme of parsedUrl
-Added scheme parameter for Session constructor

@ohamuy
Copy link
Contributor Author

ohamuy commented Jun 10, 2021

Ok so apparently removing the original function broke a lot of tests, what should I do?

.vscode/settings.json Outdated Show resolved Hide resolved
Copy link
Contributor

@maxgolov maxgolov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I think your Visual Studio code settings is probably something that we'd rather not add in here?

@maxgolov
Copy link
Contributor

maxgolov commented Jun 10, 2021

Ok so apparently removing the original function broke a lot of tests, what should I do?

Doesn't look like a lot - 3 files with tests... Fix them? 😃

image

Almost there!

@lalitb
Copy link
Member

lalitb commented Jun 11, 2021

Thank you for your contribution. Looks good to merge now :)

@lalitb lalitb merged commit 703a2a5 into open-telemetry:main Jun 11, 2021
@ohamuy ohamuy deleted the HTTPClient_Add_Url_Support branch June 18, 2021 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants