Skip to content

Conversation

@ajgarlag
Copy link
Contributor

@ajgarlag ajgarlag commented Oct 14, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

When a PSR-7 request is sent using Psr18Client, the PSR-7 request protocol version is only converted to the underlying http_version option when is set to 1.0, so we cannot control that option for 1.1 or 2.0.

I have a project where I need to dynamically force the use of protocol version 1.1 but the final request is always sent using version 2.0.

This PR add option auto_upgrade_http_version to control how the request HTTP version is handled in HttplugClient and Psr18Client.

$psr18Client = $psr18Client->withOptions(['auto_upgrade_http_version' => false]);

$request = $psr18Client->createRequest()->withProtocolVersion('1.1');

// [...]

// The request will use HTTP/1.1, whereas the defaults would upgrade to 2.0
$response = $psr18Client->sendRequest($request);

@carsonbot carsonbot added this to the 7.4 milestone Oct 14, 2025
@carsonbot carsonbot changed the title Honor psr7 protocol version Honor psr7 protocol version Oct 14, 2025
@ajgarlag
Copy link
Contributor Author

I have a few questions about the initial implementation:

  • should the property $honorRequestHttpVersion be exposed as a constructor argument?
  • should the type of the property $honorRequestHttpVersion be restricted to bool values? If so, should a deprecation be triggered when it is set to false and the protocol version is set to 1.0?

Any proposal for a better option name is welcome too.

@ajgarlag ajgarlag force-pushed the honor-psr7-protocol-version-feature branch 3 times, most recently from 6b92b39 to c9a4bbd Compare October 14, 2025 08:07
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, here are some suggestions

@carsonbot carsonbot changed the title Honor psr7 protocol version [HttpClient] Honor psr7 protocol version Oct 14, 2025
@nicolas-grekas nicolas-grekas changed the title [HttpClient] Honor psr7 protocol version [HttpClient] Add option auto_upgrade_http_version to control how the request HTTP version is handled in HttplugClient and Psr18Client Oct 14, 2025

if ('1.0' === $request->getProtocolVersion()) {
$options['http_version'] = '1.0';
if (!$this->autoUpgradeHttpVersion || '1.0' === $request->getProtocolVersion()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we deprecate the exceptional behavior for version 1.0?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't: all PSR-7 implementations default to 1.1, so if we see 1.0 here, it's on purpose.
Also no need to change something that ain't bokrne :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we see 2.0 or 3.0 here is on purpose too.

Copy link
Member

@nicolas-grekas nicolas-grekas Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'd consider explicit HTTP version selection something of the past - TLS negotiation makes it mostly useless.
I wouldn't change. The option you added is fine to reclaim control for use cases that care.

…e request HTTP version is handled in `HttplugClient` and `Psr18Client`
@nicolas-grekas nicolas-grekas force-pushed the honor-psr7-protocol-version-feature branch from a4c62dd to b6ac394 Compare October 14, 2025 08:41
@nicolas-grekas
Copy link
Member

Thank you @ajgarlag.

@nicolas-grekas nicolas-grekas merged commit ad0a07c into symfony:7.4 Oct 14, 2025
11 checks passed
This was referenced Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants