Skip to content

Refactor: Extraction of HTTP Connection Manager in FullDuplexHttpStream #10010

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

Conversation

matheusbus
Copy link

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:

    • Changes: The HTTP connection management logic has been extracted into a new class called HttpConnectionManager. This refactor allows FullDuplexHttpStream to focus on managing the data streams, while the connection logic is handled by the new class.
    • Benefit: Reduces the complexity of the FullDuplexHttpStream, promotes better maintainability, and enables easier unit testing of the connection logic.
  • Refactoring 2: Misleading Class Name:

    • Code Smell: The class name FullDuplexHttpStream was misleading, as the class actually handles two separate streams (upload and download), not a simultaneous full-duplex communication.
    • Changes: The class was renamed to HttpUploadDownloadStream to better reflect its actual functionality.
    • Benefit: The new name is clearer and more accurate, reducing potential confusion for developers working with the class.

Refactoring Techniques Applied:

  • Extract Class: The HTTP connection management logic was moved to a new class (HttpConnectionManager), which improves the cohesion of the FullDuplexHttpStream 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:

    • The refactor was manually tested to ensure that the connection establishment, stream handling, and functionality remained intact.
    • Testing included verifying both upload and download operations to ensure proper behavior after the changes.
  • Automated Testing:

    • No new automated tests were introduced. However, existing tests were run to confirm that no regressions occurred, and the system behaves as expected with the new class structure.

Proposed Changelog Entries

  • Extracted the HTTP connection management logic into a new class HttpConnectionManager.
  • Renamed the FullDuplexHttpStream class to HttpUploadDownloadStream for clarity.
  • Refactored method names to better represent the class's functionality.

Proposed Upgrade Guidelines

N/A


Submitter Checklist

  • The Jira issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate and written in the imperative mood.
  • The change has been manually tested, and the behavior has been verified.
  • No new public classes or methods require additional annotations.
  • No new deprecations have been introduced.
  • New or changed JavaScript does not use inline definitions or eval.
  • For dependency updates, relevant changelogs have been linked.
  • For new APIs, at least one consumer is referenced.

Desired Reviewers

  • @jenkinsci/core-pr-reviewers

Maintainer Checklist

  • There are at least two approvals for the pull request.
  • All conversations in the pull request are resolved.
  • The changelog entries are accurate and in the imperative mood.
  • Proper changelog labels have been set.
  • If the change needs additional upgrade steps, the upgrade-guide-needed label is set.
  • If this change should be backported to LTS, a Jira issue has been created with the lts-candidate label.

@MarkEWaite MarkEWaite added the skip-changelog Should not be shown in the changelog label Feb 11, 2025
@github-actions github-actions bot added the unresolved-merge-conflict There is a merge conflict with the target branch. label Jun 1, 2025
Copy link
Contributor

github-actions bot commented Jun 1, 2025

Please take a moment and address the merge conflicts of your pull request. Thanks!

@NotMyFault
Copy link
Member

I'll go ahead and close this PR, given the change proposed doesn't compile at all and progress has been stale for over 6 months. However, you are very much welcome to submit a new PR, which has been tested locally before submission.

@NotMyFault NotMyFault closed this Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog Should not be shown in the changelog unresolved-merge-conflict There is a merge conflict with the target branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants