Skip to content

fix: add DisableHTTP2Fallback option to respect HTTP/1.1-only transport configs#532

Closed
usernametooshort wants to merge 1 commit intoprojectdiscovery:mainfrom
usernametooshort:fix/disable-http2-fallback
Closed

fix: add DisableHTTP2Fallback option to respect HTTP/1.1-only transport configs#532
usernametooshort wants to merge 1 commit intoprojectdiscovery:mainfrom
usernametooshort:fix/disable-http2-fallback

Conversation

@usernametooshort
Copy link

Problem

When a caller explicitly configures HTTP/1.1-only transport (e.g. httpx -pr http11 which sets transport.TLSNextProto = map[string]func(...){} and GODEBUG=http2client=0), retryablehttp-go silently bypasses this restriction via the automatic HTTP/2 fallback in do.go:

if err != nil && stringsutil.ContainsAny(err.Error(), "net/http: HTTP/1.x transport connection broken: malformed HTTP version ...") {
    resp, err = c.HTTPClient2.Do(req.Request)  // ← ignores HTTP/1.1-only config
}

This means -pr http11 in httpx has no effect for servers that respond with HTTP/2.

See: projectdiscovery/httpx#2240

Fix

Add DisableHTTP2Fallback bool to Options. When set, the HTTPClient2.Do fallback is skipped, respecting the caller's explicit protocol choice.

if err != nil && !c.options.DisableHTTP2Fallback && stringsutil.ContainsAny(...) {
    resp, err = c.HTTPClient2.Do(req.Request)
}

Usage (httpx side)

In httpx when Protocol == "http11":

retryablehttpOptions.DisableHTTP2Fallback = true

This is a non-breaking change — existing callers that do not set the option retain the current fallback behavior.

When a caller explicitly sets HTTP/1.1-only transport (e.g. httpx -pr http11),
retryablehttp-go's automatic HTTP/2 fallback in do.go would silently bypass
this restriction. This introduces DisableHTTP2Fallback in Options which, when
set, skips the HTTPClient2.Do fallback on malformed HTTP/2 errors.

Fixes the underlying cause of projectdiscovery/httpx#2240.
@neo-by-projectdiscovery-dev
Copy link

neo-by-projectdiscovery-dev bot commented Mar 6, 2026

Neo - PR Security Review

No security issues found

Highlights

  • Adds DisableHTTP2Fallback option to allow callers to opt out of automatic HTTP/2 fallback
  • Preserves existing behavior by default (non-breaking change)
  • Enables httpx -pr http11 flag to properly enforce HTTP/1.1-only communication

Comment @neo help for available commands. · Open in Neo

usernametooshort added a commit to usernametooshort/httpx that referenced this pull request Mar 6, 2026
… protocol is set

When -pr http11 is used, httpx correctly sets TLSNextProto={} and
GODEBUG=http2client=0 to force HTTP/1.1. However retryablehttp-go's
automatic HTTP/2 fallback in do.go silently bypasses this:

  if err is malformed HTTP/2 response {
      resp, err = c.HTTPClient2.Do(req.Request)  // <- ignores http11 config
  }

This commit sets retryablehttpOptions.DisableHTTP2Fallback=true when
Protocol=="http11", ensuring the HTTP/1.1-only requirement is honoured
end-to-end.

Depends on: projectdiscovery/retryablehttp-go#532
Fixes: projectdiscovery#2240
usernametooshort added a commit to usernametooshort/httpx that referenced this pull request Mar 6, 2026
… protocol is set

When -pr http11 is used, httpx correctly sets TLSNextProto={} and
GODEBUG=http2client=0 to force HTTP/1.1. However retryablehttp-go's
automatic HTTP/2 fallback in do.go silently bypasses this:

  if err is malformed HTTP/2 response {
      resp, err = c.HTTPClient2.Do(req.Request)  // <- ignores http11 config
  }

This commit sets retryablehttpOptions.DisableHTTP2Fallback=true when
Protocol=="http11", ensuring the HTTP/1.1-only requirement is honoured
end-to-end.

Depends on: projectdiscovery/retryablehttp-go#532
Fixes: projectdiscovery#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.

2 participants