refactor: use trait bound accept
fn to reduce duplicate logic
#24
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.
This PR is two fold in factoring:
First off, at the moment both
TcpProxy
andHttpProxy
both start, regardless of whether there is anything configured against thoselisteners
. This isn't a huge deal, but it's an easy win to quickly check the provided configuration on startup and simply gate the start of either proxy based on whether thatProtocol
type actually exists.Second of it more around general software design. When I initially introduced the
Proxy
trait in #15 I was thinking about it in the wrong way, whereby I still had theaccept
function defined within the trait, meaning that there was a tonne of duplicated logic and the same changes being done, just in a different place. Instead, I've now done what I previously hoped and pulled out common functionality, i.e. theaccept
function has become a trait-bound function, requiring only the implementation-specific details of actually proxying connections to be left to to be filled in by those which satisfy thetrait
- the reasoning here is that implementations may differ, such as HTTP being concerned with L7 (HTTP method, request path etc.), but the initial acceptance logic should remain the same.