Skip to content

Regression from #65: circular-require warning when cookie_jar is required before cookie (1.1.6) #66

@lineoffligbot

Description

@lineoffligbot

Summary

The fix for #65 (shipped in 1.1.6) resolves the warning for isolated loads of http/cookie or http/cookie_jar, but introduces the same warning in a different scenario: loading http/cookie_jar before http/cookie.

Minimal reproduction

$ ruby --version
ruby 4.0.1 (...) [x86_64-darwin25]
$ gem list http-cookie
http-cookie (1.1.6)
$ ruby -w -e 'require "http/cookie_jar"; require "http/cookie"'
warning: loading in progress, circular require considered harmful -
  .../http-cookie-1.1.6/lib/http/cookie.rb
warning: Expected http/cookie to define HTTP::Cookie but it didn't

Why the 1.1.6 fix doesn't cover this

  • Before 1.1.6: cookie_jar.rb did require "http/cookie" eagerly, so loading cookie_jar first would fully load cookie before returning. No warning in this path.
  • After 1.1.6 (commit 93bf8de): cookie_jar.rb now does module HTTP; autoload :Cookie, "http/cookie"; end. The eager require is gone, so only the autoload registration persists.
  • When http/cookie is then required, cookie.rb:3 requires http/cookie/version, and version.rb:2 opens class Cookie inside module HTTP. Ruby resolves the Cookie constant, finds the registered autoload, and fires it for the still-loading http/cookie.rb — circular require warning.

Real-world impact

The http gem (>= 5) triggers this because lib/http.rb loads http/session before http/response:

  • http/session.rb:5require "http/cookie_jar" (registers the autoload)
  • http/response.rb:11require "http/cookie" (triggers it)

So any require "http" under -w / Ruby 4.0 prints the warning.

Suggested direction

Defining HTTP::Cookie (even as an empty shell) at the top of cookie.rb before require 'http/cookie/version' would satisfy the autoload without cycling. Alternatively, moving the VERSION constant out of a class-reopen (e.g. assigning HTTP::Cookie::VERSION after the class is defined) sidesteps the constant lookup during load. Happy to send a PR if there's agreement on the approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions