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

HTTPClient : Support for full URL argument instead of host & port #812

Closed
lalitb opened this issue Jun 1, 2021 · 10 comments
Closed

HTTPClient : Support for full URL argument instead of host & port #812

lalitb opened this issue Jun 1, 2021 · 10 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers priority:p2 Issues that are not blocking release:required-for-ga To be resolved before GA release

Comments

@lalitb
Copy link
Member

lalitb commented Jun 1, 2021

As discussed here:

  • HttpClient::CreateSession method should support passing full URL as an argument instead of host and port (or perhaps support both). This would be then consistent with HttpClientSync::Get(url) and HttpClientSync::Post(url) methods.
  • Validate if HTTPS URL is parsed successfully, and supported for curl implementation. Remove TODO from here once https works/fixed:

host_ = "http://" + host; // TODO - https support

@lalitb lalitb added the bug Something isn't working label Jun 1, 2021
@lalitb lalitb changed the title HTTPClient : Support for url string instead of host + port HTTPClient : Support for full URL argument instead of host & port Jun 1, 2021
@lalitb lalitb added good first issue Good for newcomers release:after-ga To be resolved after GA release priority:p2 Issues that are not blocking release:required-for-ga To be resolved before GA release and removed release:after-ga To be resolved after GA release labels Jun 1, 2021
@ohamuy
Copy link
Contributor

ohamuy commented Jun 2, 2021

Hey! Could I pick up this issue?

@alolita

@ohamuy
Copy link
Contributor

ohamuy commented Jun 2, 2021

@lalitb Would you rather have me allow for HttpClient::CreateSession to have the template have multiple parameters, one for host/port and one for a full url? Or would you rather have me change the current implementation to simply fix https and work for full url

@ohamuy
Copy link
Contributor

ohamuy commented Jun 2, 2021

I’d like to work on this issue. Can you please assign this to me? @alolita

@lalitb
Copy link
Member Author

lalitb commented Jun 2, 2021

Thanks @ohamuy - assigned to you now. We can use function overloading to support both unless you see benefit with templates?

@ohamuy
Copy link
Contributor

ohamuy commented Jun 3, 2021

Yea @lalitb I could definitely do function overloading. Also how do we know whether the user wants http or https appended if they only provide the host and port? Also for testing would I use Bazel or is there some other way to test my code?

@lalitb
Copy link
Member Author

lalitb commented Jun 3, 2021

Yea @lalitb I could definitely do function overloading. Also how do we know whether the user wants http or https appended if they only provide the host and port? Also for testing would I use Bazel or is there some other way to test my code?

default should be always http unless user explicitly specified https. This should be irrespective of whether port number is 80 or 443.

@ohamuy
Copy link
Contributor

ohamuy commented Jun 3, 2021

Hey @lalitb @reyang I wrote this block of code overloading the Session to allow for url input. This utilizes the urlparser in the common folder. What would you like me to return if it doesn't successfully parse? Nullptr? Also this code compiles successfully using Bazel

Are there any additional features besides this url addition that are needed (like in the constructor or implementation)? Also how should I validate that this overload function works properly? Should I create and run an example in the examples folder or is the http Bazel example sufficient?

 std::shared_ptr<http_client::Session> CreateSession(nostd::string_view url) noexcept override
  {
	  auto parsedUrl = common::UrlParser(std::string(url));
	  if (!parsedUrl.success_) {
		  //return std::make_shared<Session>();
	  }
	  auto session    = std::make_shared<Session>(*this, parsedUrl.host_, parsedUrl.port_);
	  auto session_id = ++next_session_id_;
	  session->SetId(session_id);
	  sessions_.insert({session_id, session});
	  return session;
  }

@lalitb
Copy link
Member Author

lalitb commented Jun 4, 2021

@ohamuy - Your approach looks good. We can return the Session object with an empty/non-existent host, and default port(80). And let the actual connection failure get caught at ResponseHandler level:

 std::shared_ptr<http_client::Session> CreateSession(nostd::string_view url) noexcept override
  {
	  auto parsedUrl = common::UrlParser(std::string(url));
	  if (!parsedUrl.success_) {
                  //TBD - Log error once error handler is supported
		  return std::make_shared<Session>(*this, "empty-host", 80);
	  }
	  auto session    = std::make_shared<Session>(*this, parsedUrl.host_, parsedUrl.port_);
	  auto session_id = ++next_session_id_;
	  session->SetId(session_id);
	  sessions_.insert({session_id, session});
	  return session;
  }

While using ,

  auto session = httpClient.createSession("localhost", 8000);
  auto request = session->CreateRequest();
  request->AddHeader(..);
  SimpleResponseHandler res_handler;
  session->SendRequest(res_handler);

res_handler will catch the connection error.

@ohamuy
Copy link
Contributor

ohamuy commented Jun 4, 2021

@lalitb Ok great, I'll add these changes and get a PR ready (will have to get it reviewed first within Amazon!)

@ohamuy
Copy link
Contributor

ohamuy commented Jun 11, 2021

We can close this issue now, correct? @lalitb

@lalitb lalitb closed this as completed Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers priority:p2 Issues that are not blocking release:required-for-ga To be resolved before GA release
Projects
None yet
Development

No branches or pull requests

2 participants