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

feat: eventsource client #1

Merged
merged 58 commits into from
Mar 29, 2023
Merged

Conversation

cwaldren-ld
Copy link
Contributor

@cwaldren-ld cwaldren-ld commented Mar 28, 2023

Background

This introduces an EventSource client, based on boost::beast.

Beast provides HTTP primitives - such as message representations and response parsers - and a convenient websocket library.

I searched for a 3rd party EventSource library, but I couldn't find one that utilized asio. There are tons of websocket libraries, though; maybe we should get on board.

The reasons it's important to write this on top of asio are:

  • It's robust and cross-platform.
  • It's part of boost, which is easily obtainable and carries a standard level of quality and documentation.
  • We want all the network operations in the SDK to play nice together.*

*Such as running on a single thread.

Work remaining (future PRs)

  • Follow redirects
  • Automatic retries
  • Get the SSE contract tests going in CI

Builder (public)

This contains config options. Calling build() gives you a shared_ptr<Client>.

Client (public)

This is an abstract base class containing run() and stop() methods.

Event (public)

Contains event type, ID, and data. This is the boundary between the Client and the user.

Session (implementation detail)

This is a base class, and implements the main state machine for dealing with the SSE protocol.

It allows for some specialization via base classes in order to implement plaintext (for contract tests) and TLS (for production.) Because of the templated nature of beast, it's kinda awkward.

The async operations involve resolving the IP, connecting, sending the initial request, and reading chunks. It invokes a parser which breaks the chunks into events, which are then forwarded back to the user via callback.

EncryptedClient < Session, Client (implementation detail)

This is a Session, except it performs a TLS handshake and uses a beast::ssl_stream.

PlaintextClient < Session, Client (implementation detail)

This is a Session which uses a plain old beast::tcp_stream.

@cwaldren-ld
Copy link
Contributor Author

Gonna merge. I can't figure out how to suppress those protected lints (using //NOLINT), so I'll try again another day.

@cwaldren-ld cwaldren-ld merged commit ab2b0fe into main Mar 29, 2023
@cwaldren-ld cwaldren-ld deleted the cw/sc-193985/eventsource-client branch March 29, 2023 21:05
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.

2 participants