So the answer is really simple, you're making a HTTP 1.0 request while the Twitter API requires a HTTP 1.1 request.
The source of the problem resides in the Request object. In order to work around that I've quickly created two more classes. RequestData11:
<?php
use React\HttpClient\RequestData;
class RequestData11 extends RequestData
{
public function setProtocolVersion($version)
{
}
}
And Client11:
<?php
use React\EventLoop\LoopInterface;
use React\HttpClient\Request;
use React\SocketClient\ConnectorInterface;
class Client11
{
private $connectionManager;
private $secureConnectionManager;
public function __construct(ConnectorInterface $connector, ConnectorInterface $secureConnector)
{
$this->connector = $connector;
$this->secureConnector = $secureConnector;
}
public function request($method, $url, array $headers = array())
{
$requestData = new RequestData11($method, $url, $headers);
$connectionManager = $this->getConnectorForScheme($requestData->getScheme());
return new Request($connectionManager, $requestData);
}
private function getConnectorForScheme($scheme)
{
return ('https' === $scheme) ? $this->secureConnector : $this->connector;
}
}
You normally would create a new client like this:
<?php
$client = $httpClientFactory->create($loop, $dnsResolver);
Instead you'll have to create it this way:
<?php
$connector = new Connector($loop, $dnsResolver);
$secureConnector = new SecureConnector($connector, $loop);
$client = new Client11($connector, $secureConnector);
This forces the client to use HTTP 1.1, beware though, the http-client is a 1.0 client so forcing it to 1.1 should only be done when you know what you're doing.
Note that you didn't lock the react\http-client version in your composer file so I have no clue what version you're using and the bove code might not work because of that.