-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
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
Gonna merge. I can't figure out how to suppress those |
This was referenced May 8, 2023
Merged
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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:*Such as running on a single thread.
Work remaining (future PRs)
Builder (public)
This contains config options. Calling
build()
gives you ashared_ptr<Client>
.Client (public)
This is an abstract base class containing
run()
andstop()
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 abeast::ssl_stream
.PlaintextClient < Session, Client (implementation detail)
This is a
Session
which uses a plain oldbeast::tcp_stream
.