Skip to content

[HttpClient] HTTP/2 stream 0 was not closed cleanly #60244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lyrixx opened this issue Apr 18, 2025 · 8 comments
Closed

[HttpClient] HTTP/2 stream 0 was not closed cleanly #60244

lyrixx opened this issue Apr 18, 2025 · 8 comments

Comments

@lyrixx
Copy link
Member

lyrixx commented Apr 18, 2025

Symfony version(s) affected

7.2.4

Description

When I request some URL, I get the following error

Uncaught Symfony\Component\HttpClient\Exception\TransportException: HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2) for "https://www.celine.com/".

However, it works well in my browser and with curl

How to reproduce

<?php

require __DIR__ . '/vendor/autoload.php';

use Symfony\Component\HttpClient\HttpClient;

$r = HttpClient::create()->request('GET', 'https://www.celine.com/');

dump(
    $r->getStatusCode(),
    $r->getHeaders(false),
    $r->getContent(false),
);

Possible Solution

No response

Additional Context

No response

@abdalmassih-publicplan
Copy link

abdalmassih-publicplan commented Apr 22, 2025

Hello,

I was able to reproduce your issue. I believe the main issue here is that many servers (especially those behind strict load balancers or anti-bot tools) have somewhat finicky HTTP/2 implementations. Forcing HTTP/1.1 along with setting the User-Agent header fixed it for me. Here's my solution after trying out different request options combinations:

Image

Image

@nicolas-grekas
Copy link
Member

No need to switch to HTTP/1.1: just setting a User-Agent fixes it:

['headers' => ['User-Agent' => 'a/b']]

This looks related to #50052

Help wanted to figure out a proper user-agent that'd be more mundane for the rest of the world (and celine.com in this case)

@stof
Copy link
Member

stof commented Apr 22, 2025

Well, if they have an anti-bot protection, it could make sense that the default User-Agent of symfony/http-client is detected as a bot in their system (which would actually be correct in your case).

@abdalmassih-publicplan
Copy link

It doesn't work for me without setting the HTTP version (tried also with another user-agent: Mozilla/5.0 (Macintosh)'):

"HTTP/2 stream 1 was not closed cleanly: INTERNAL_ERROR (err 2) for "https://www.celine.com/"."

Did you try it on your own?

@nicolas-grekas
Copy link
Member

Yep, I tried with a/b and it worked on my side.
Anti-bot detection is a bit dumb :)

@lyrixx
Copy link
Member Author

lyrixx commented Apr 22, 2025

Oh! We already have an User-Agent: Mozilla/5.0 (compatible; redirection-io/1.0; +https://redirection.io/ But with this one it's also broken.

Yep, I tried with a/b and it worked on my side. Anti-bot detection is a bit dumb :)

So true !

@lyrixx
Copy link
Member Author

lyrixx commented Apr 22, 2025

I don't know what we can do here? Can we enhance the exception message? If not, let's close this issue

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 22, 2025

Closing, the issue is on this stupid antibot. About the error message, not sure we can improve. Curl is likely right: the server behaved not politely. 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants