Skip to content

Conversation

@cwaldren-ld
Copy link
Contributor

@cwaldren-ld cwaldren-ld commented May 5, 2023

This PR updates the eventsource and requester libraries with foxy, a slightly higher level networking lib built on asio and beast.

The main advantages of using this library over homegrown code are:

  • It supports TLS/plaintext clients
  • It uses the CompletionToken system for all operations
  • It supports timeouts for all operations

I've tried to do the most minimally invasive thing here, which was:

  1. Introduce a FoxyClient alongside the Encrypted and Plaintext clients in both AsioRequester and Eventsource
  2. Swap the calling code to use FoxyClient
  3. Delete Encrypted and Plaintext client

This means there is more we could do to take advantage of foxy.

For example, in AsioRequester we could implement retries/redirects in terms of composed asynchronous operations.

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #199702: Refactor HTTP operations to use foxy library.

@cwaldren-ld
Copy link
Contributor Author

Adding foxy broke gtest; trying to fix. Issue is that its unit tests require Catch2, which I didn't want to pull in.

@cwaldren-ld cwaldren-ld requested a review from kinyoklion May 5, 2023 17:22
client_builder.write_timeout(http_properties.WriteTimeout());

client_builder.connect_timeout(http_properties.ConnectTimeout());

Copy link
Contributor Author

@cwaldren-ld cwaldren-ld May 5, 2023

Choose a reason for hiding this comment

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

The TODO here is because the SSE stream has a heartbeat, so it's not quite the same as a generic HTTP request read timeout.

For instance, it might be appropriate to have a 10 second read timeout on a poll request or whatever, but that could be too short/long for the heartbeat.

I don't know if the heartbeat interval is actually documented anywhere. Will look.

return *maybe_val;
}
return boost::none;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like there's a better way to do this conversion. The gist is foxy takes an boost::optional<context&>, but we're generally using std::optional (which doesn't support references) or std::shared_ptr, in this case.

Copy link
Member

Choose a reason for hiding this comment

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

I have encountered a similar problem a dozen times. Drives me crazy. With std::optional you have to use the reference_wrapper, which is terrible.

->Run();
std::string service =
request->Port().value_or(request->Https() ? "https" : "http");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's happening here is we're determining whether or not to pass in a ssl_context based on the presence or absence of https as the scheme of the URL.

If you instead pass a port, it's going to pass that in instead - without an ssl_context. So if you did :443, you better use https:// as the scheme if that's a TLS server.

Copy link
Member

Choose a reason for hiding this comment

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

That sounds 100% correct.

Copy link
Member

Choose a reason for hiding this comment

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

(For a URL)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want to support snews:// we just case about maybe some close cases, like domain sockets. So, it would still be fine, you don't need a TLS domain socket.

port_ = uri_components->port();
} else {
port_ = is_https_ ? "443" : "80";
}
Copy link
Contributor Author

@cwaldren-ld cwaldren-ld May 5, 2023

Choose a reason for hiding this comment

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

No longer attempting to set a default port - we can't assume these ports will be correct.

Copy link
Member

Choose a reason for hiding this comment

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

If it handles this, then that is cool. But the RFCs for HTTP and HTTPs specify the default ports. I guess the only way we could not be sure was if it was not http/https.

Copy link
Member

Choose a reason for hiding this comment

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

(Technically adding port 21 for FTP would have covered URL cases, but if we are supporting URIs, then that is a different case. Which is probably good to support for people who do strange stuff, even if most of the SDKs don't).

@cwaldren-ld cwaldren-ld requested review from kinyoklion and removed request for kinyoklion May 5, 2023 18:49
Copy link
Member

@kinyoklion kinyoklion left a comment

Choose a reason for hiding this comment

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

Looks good.

Curious to see if it fixes the bigobj requirement for windows.

@cwaldren-ld cwaldren-ld merged commit 33e92df into main May 5, 2023
@cwaldren-ld cwaldren-ld deleted the cw/sc-199702/foxy-eventsource-asio-requester branch May 5, 2023 22:12
This was referenced Oct 23, 2023
@github-actions github-actions bot mentioned this pull request May 13, 2024
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.

3 participants