8000 [HttpClient] PHP Fatal error: Uncaught TypeError: Argument 2 passed to Symfony\Component\HttpClient\Chunk\DataChunk::__construct() must be of the type string, null given · Issue #37923 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient] PHP Fatal error: Uncaught TypeError: Argument 2 passed to Symfony\Component\HttpClient\Chunk\DataChunk::__construct() must be of the type string, null given #37923

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
ghost opened this issue Aug 23, 2020 · 3 comments

Comments

@ghost
Copy link
ghost commented Aug 23, 2020

Symfony version(s) affected: 5.1.3

Description
Any idea why this happening? This url was in a loop and crashes the entire script.

How to reproduce

<?php

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

use Symfony\Component\HttpClient\HttpClient;

$client = HttpClient::create();
$response = $client->request('GET', 'http://123c.vn/');

Additional context

PHP Fatal error:  Uncaught TypeError: Argument 2 passed to Symfony\Component\HttpClient\Chunk\DataChunk::__construct() must be of the type string, null given, called in /bug/vendor/symfony/http-client/Response/ResponseTrait.php on line 363 and defined in /bug/vendor/symfony/http-client/Chunk/DataChunk.php:26
Stack trace:
#0 /bug/vendor/symfony/http-client/Response/ResponseTrait.php(363): Symfony\Component\HttpClient\Chunk\DataChunk->__construct(0, NULL)
#1 /bug/vendor/symfony/http-client/Response/ResponseTrait.php(237): Symfony\Component\HttpClient\Response\CurlResponse::stream(Array)
#2 /bug/vendor/symfony/http-client/Response/ResponseTrait.php(300): Symfony\Component\HttpClient\Response\CurlResponse::initialize(Object(Symfony\Component\HttpClient\Response\CurlResponse))
#3 /bug/vendor/symfony/http-client/Response/CurlResponse.php(196): Symfony\Component\HttpClient\Response\CurlResponse->doDestruct()
#4 [internal  in /bug/vendor/symfony/http-client/Chunk/DataChunk.php on line 26

Fatal error: Uncaught TypeError: Argument 2 passed to Symfony\Component\HttpClient\Chunk\DataChunk::__construct() must be of the type string, null given, called in /bug/vendor/symfony/http-client/Response/ResponseTrait.php on line 363 and defined in /bug/vendor/symfony/http-client/Chunk/DataChunk.php:26
Stack trace:
#0 /bug/vendor/symfony/http-client/Response/ResponseTrait.php(363): Symfony\Component\HttpClient\Chunk\DataChunk->__construct(0, NULL)
#1 /bug/vendor/symfony/http-client/Response/ResponseTrait.php(237): Symfony\Component\HttpClient\Response\CurlResponse::stream(Array)
#2 /bug/vendor/symfony/http-client/Response/ResponseTrait.php(300): Symfony\Component\HttpClient\Response\CurlResponse::initialize(Object(Symfony\Component\HttpClient\Response\CurlResponse))
#3 /bug/vendor/symfony/http-client/Response/CurlResponse.php(196): Symfony\Component\HttpClient\Response\CurlResponse->doDestruct()
#4 [internal  in /bug/vendor/symfony/http-client/Chunk/DataChunk.php on line 26

Tried this on the terminal

curl -I http://123c.vn/
curl: (1) Received HTTP/0.9 when not allowed
@fancyweb
Copy link
Contributor

Status: reviewed

The server header data are never sent or at least after the first content chunk. Therefore, the CURLOPT_HEADERFUNCTION callback is never called and the FirstChunk is never yield. That means we have to handle the first string chunk before the response write buffer is set. We do not support that. WDYT of throwing @nicolas-grekas?

@nicolas-grekas
Copy link
Member
nicolas-grekas commented Aug 31, 2020
curl --http0.9 -v http://123c.vn/
*   Trying 120.138.69.92:80...
* TCP_NODELAY set
* Connected to 123c.vn (120.138.69.92) port 80 (#0)
> GET / HTTP/1.1
> Host: 123c.vn
> User-Agent: curl/7.68.0
> Accept: */*
> 
<html xmlns="http://www.w3.org/1999/xhtml"><head>[...]

This is HTTP/0.9, and the code is not prepared for this.
This should throw a TransportException, no need to add support for this IMHO.
@anaggh works for you?
Anyone up for a PR?

@ghost
Copy link
Author
ghost commented Sep 1, 2020

Yup works with the --http0.9 flag! TransportException would be nice. Thanks!

nicolas-grekas added a commit that referenced this issue Sep 11, 2020
…TP/0.9 (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] fail properly when the server replies with HTTP/0.9

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37923
| License       | MIT
| Doc PR        | -

Commits
-------

96759af [HttpClient] fail properly when the server replies with HTTP/0.9
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

4 participants
0