Skip to content

Add H2C fallback to HTTP/1.1 support - #166

Merged
3dgiordano merged 1 commit into
developmentfrom
H2C-FALLBACK-HTTP-1.1
Aug 25, 2026
Merged

Add H2C fallback to HTTP/1.1 support#166
3dgiordano merged 1 commit into
developmentfrom
H2C-FALLBACK-HTTP-1.1

Conversation

@3dgiordano

Copy link
Copy Markdown
Collaborator

This pull request refines the handling of HTTP/2 cleartext (h2c) upgrade attempts in HTTP2JettyClient, ensuring that requests are only retried when the server explicitly refuses the upgrade, and not when it simply ignores the upgrade headers and serves the request over HTTP/1.1. This prevents duplicate requests and potential side effects, and improves efficiency by caching origins that do not support h2c. Comprehensive tests have been added to verify the new behavior.

Core logic improvements

  • Introduced H2C_UPGRADE_REFUSED_STATUSES, a set of HTTP status codes (400, 426, 501, 505) that indicate the server refused the h2c upgrade, and updated shouldRetryAfterFailedH2cUpgrade to only retry requests in these cases instead of retrying whenever HTTP/2 was not negotiated. [1] [2] [3]
  • Modified header-setting logic in setHeaders to skip sending h2c upgrade headers to origins already known to be HTTP/1.1-only, preventing unnecessary upgrade attempts and reducing request overhead.

Testing enhancements

  • Added new tests to HTTP2JettyClientH2cFallbackTest to verify that:
    • Requests to HTTP/1.1-only servers are not retried and only one request is sent per sampler.
    • Only explicit upgrade refusals trigger a retry, while regular HTTP/1.1 responses do not.
    • The HTTP/1.1-only cache prevents repeated upgrade attempts to the same origin. [1] [2]
  • Improved test infrastructure by allowing the test HTTP/1.1 server to count requests for more precise assertions.

Test utility improvements

  • Utilized Mockito to mock ContentResponse objects in tests, allowing for direct and reliable verification of retry logic based on different status codes. [1] [2] [3]

Only when H2C not is supported
@3dgiordano
3dgiordano merged commit 32f56d1 into development Aug 25, 2026
2 checks passed
@3dgiordano
3dgiordano deleted the H2C-FALLBACK-HTTP-1.1 branch August 25, 2026 08:18
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.

1 participant