Skip to content

feat: add DisableHTTP2Fallback option to prevent automatic HTTP/2 fallback#526

Closed
MrLawrenceKwan wants to merge 1 commit intoprojectdiscovery:mainfrom
MrLawrenceKwan:fix-http2-fallback
Closed

feat: add DisableHTTP2Fallback option to prevent automatic HTTP/2 fallback#526
MrLawrenceKwan wants to merge 1 commit intoprojectdiscovery:mainfrom
MrLawrenceKwan:fix-http2-fallback

Conversation

@MrLawrenceKwan
Copy link

Description

This PR adds a new DisableHTTP2Fallback option to the client Options struct, allowing clients to disable the automatic fallback to HTTP/2 when encountering malformed HTTP/2 errors.

Context

This change is needed to fix projectdiscovery/httpx#2240, where the -pr http11 flag was being ignored because retryablehttp-go would automatically fallback to HTTP/2 on certain errors.

Changes

  1. Added DisableHTTP2Fallback field to Options struct: When set to true, the client will not automatically switch to HTTP/2 on malformed HTTP version errors.

  2. Updated do.go to respect the option: The HTTP/2 fallback logic now checks c.options.DisableHTTP2Fallback before attempting the fallback.

Behavior

  • Default (false): Maintains current behavior - automatically fallback to HTTP/2 on malformed HTTP/2 errors
  • When enabled (true): HTTP/1.x transport errors are handled according to the retry policy without switching protocols

Use Case

This is particularly useful when clients explicitly want to use HTTP/1.1 only and prefer to handle errors according to the retry policy rather than automatically switching to HTTP/2.

Related Issues

Testing

This change has been tested with httpx and works correctly to enforce HTTP/1.1 when the protocol flag is set.

…lback

This option allows clients to disable the automatic fallback to HTTP/2
when encountering malformed HTTP/2 errors. This is useful when a client
explicitly wants to use HTTP/1.1 only and have errors handled according
to the retry policy instead of automatically switching protocols.

Fixes projectdiscovery/httpx#2240
@Mzack9999
Copy link
Member

The underlying issue (httpx#2240) has been resolved at the httpx level — the HTTP/1.1 protocol preference is now correctly enforced without requiring changes to retryablehttp-go. Closing as the original bounty issue is already complete. Thanks for the contribution.

@Mzack9999 Mzack9999 closed this Mar 22, 2026
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.

-pr http11 flag is ignored on retryablehttp-go due to HTTP/2 fallback

3 participants