Skip to content

Guard Net::HTTPHeader#content_length spec by net-http version - #1404

Merged
andrykonchin merged 1 commit into
ruby:masterfrom
mrhoribu:net-http-content-length-version
Oct 23, 2026
Merged

andrykonchin merged 1 commit into
ruby:masterfrom
mrhoribu:net-http-content-length-version

Conversation

@mrhoribu

@mrhoribu mrhoribu commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The strict Content-Length parsing came from net-http 0.10.0 (ruby/net-http@23e859e92, ruby/net-http#324), not from a Ruby release. On Ruby 4.0 with net-http updated to 0.10.0, the ruby_version_is ""..."4.1" spec runs against the strict implementation and raises Net::HTTPHeaderSyntaxError: wrong Content-Length format: 123valid.

This PR guards both examples with version_is Net::HTTP::VERSION, "0.10.0".

Why not a Ruby version guard

No Ruby version boundary matches this behavior change:

  • Every 4.0.x release, including 4.0.7, 4.0.8 and 4.0.9, ships net-http 0.9.1 in lib/net/http.rb, which still parses leniently. Ruby first ships 0.10.0 on master (4.1).
  • net-http is a default gem, so it can be updated without changing Ruby. RubyInstaller2's 4.0.9 build had gems/4.0.0/gems/net-http-0.10.0 installed on top of the default 0.9.1, so the strict implementation was loaded even though RUBY_VERSION was 4.0.9.
  • With ruby_version_is "4.0.9", a stock 4.0.9 with net-http 0.9.1 would fail the strict example. With the current "4.1", any 4.0.x with an updated net-http fails the lenient example.

Guarding on Net::HTTP::VERSION follows the existing convention for default gems that are commonly updated separately from Ruby: BigDecimal::VERSION (10 guards), OpenSSL::VERSION (2) and StringIO::VERSION (1) in library/.

Seen in RubyInstaller2 CI on 4.0.9: https://github.com/oneclick/rubyinstaller2/actions/runs/39949977572/job/120434751465

Checked with mspec-run library/net-http/httpheader/content_length_spec.rb:

  • 4.0.5 (net-http 0.9.1): passes
  • 4.0.5 + net-http 0.10.0: master has 1 error, branch passes
  • 4.0.9 (net-http 0.9.1): passes
  • 4.1.0-preview1 (net-http 0.10.0): passes

🤖 Generated with Claude Code

Strict Content-Length parsing came with net-http 0.10.0, not with a Ruby
version: Ruby 4.0.x ships net-http 0.9.1 by default, but updating the gem
on it brings the strict behavior. Guard on Net::HTTP::VERSION instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrykonchin

Copy link
Copy Markdown
Member

Thank you!

@andrykonchin
andrykonchin merged commit 417be8a into ruby:master Oct 23, 2026
14 checks passed
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