Visitar URL original
[4.x] Apply the default user agent in Http instead of the factory by Hackwar · Pull Request #94 · joomla-framework/http · GitHub
Skip to content

[4.x] Apply the default user agent in Http instead of the factory - #94

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-default-user-agent
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-default-user-agent

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

The default user agent Mozilla/5.0 Joomla!/Framework, backported from the CMS in ba2a2b9, was applied in HttpFactory::getHttp() only:

  • a client created with new Http() (or one using a transport from getAvailableDriver()) sent no user agent, or cURL's/PHP's, so the behaviour depended on how the client was built;
  • the factory wrote the default into the $options it was given. With an ArrayAccess object such as a Registry or ArrayObject, the caller's object was modified in place.

Http::makeTransportRequest() now uses the userAgent option or, if none is set, the default, without writing it back, and the factory no longer touches the options. Visible difference: (new HttpFactory())->getHttp()->getOption('userAgent') is now null unless the option was set; the user agent that is sent is the same.

The finding also suggests a non-browser user agent such as Joomla-Framework-Http/4. That was not changed here, because the current string was chosen deliberately in the backport; it is easy to do separately if wanted.

Testing Instructions

Tests/HttpUserAgentTest.php (new, mocked transport):

  • new Http() passes the default user agent to the transport (before: null);
  • a configured userAgent is passed;
  • HttpFactory::getHttp() leaves an ArrayObject of options unchanged (before: userAgent was added).

Documentation Changes Required

docs/classes/HttpFactory.md: a paragraph on the default user agent and the userAgent option.

🤖 Generated with Claude Code

The default user agent backported from the CMS was only set by
HttpFactory::getHttp(), so a client created with new Http() or a transport
from getAvailableDriver() sent none, and the factory wrote the default into
the caller's options, modifying an ArrayAccess object in place.

Apply the default in Http::makeTransportRequest() when no userAgent option
is set, without writing it back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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