Refactor: Extraction of HTTP Connection Manager in FullDuplexHttpStream #10010
+128
−128
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.
Pull Request - Extraction of HTTP Connection Manager in
FullDuplexHttpStream.java
Summary of the Change
This pull request refactors the
FullDuplexHttpStream
class by extracting the HTTP connection management logic into a separate class. This change improves the maintainability, readability, and testability of the code. Additionally, the class name have been updated to reflect the actual functionality more clearly.Code Smells Identified:
Long Method: The
FullDuplexHttpStream
class method was overly long, handling both the HTTP connection creation and data transport logic, making it complex and difficult to understand.Single Responsibility Principle Violation: The class was managing both the HTTP connection setup and the data transport, which violated the single responsibility principle.
Duplicated Code: Connection configuration logic (such as establishing the connection, setting request methods, headers, etc.) was repeated for both upload and download streams.
Refactoring Details:
Refactoring 1: Extract HTTP Connection Logic:
HttpConnectionManager
. This refactor allowsFullDuplexHttpStream
to focus on managing the data streams, while the connection logic is handled by the new class.FullDuplexHttpStream
, promotes better maintainability, and enables easier unit testing of the connection logic.Refactoring 2: Misleading Class Name:
FullDuplexHttpStream
was misleading, as the class actually handles two separate streams (upload and download), not a simultaneous full-duplex communication.HttpUploadDownloadStream
to better reflect its actual functionality.Refactoring Techniques Applied:
Extract Class: The HTTP connection management logic was moved to a new class (
HttpConnectionManager
), which improves the cohesion of theFullDuplexHttpStream
class.Rename Class: The class was renamed to reflect the true nature of the class (upload/download streams), resolving the misleading name issue.
Testing Done
Manual Testing:
Automated Testing:
Proposed Changelog Entries
HttpConnectionManager
.FullDuplexHttpStream
class toHttpUploadDownloadStream
for clarity.Proposed Upgrade Guidelines
N/A
Submitter Checklist
eval
.Desired Reviewers
Maintainer Checklist
upgrade-guide-needed
label is set.lts-candidate
label.