Skip to content

Instantly share code, notes, and snippets.

@kelunik
Created January 23, 2018 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelunik/4debe50bdb72085f533bbe33a4d9ef7d to your computer and use it in GitHub Desktop.
Save kelunik/4debe50bdb72085f533bbe33a4d9ef7d to your computer and use it in GitHub Desktop.
<?php
require __DIR__ . "/vendor/autoload.php";
use Amp\Promise;
$client = new Http\Adapter\Artax\Client;
$request1 = new GuzzleHttp\Psr7\Request("GET", "http://example.com/");
print $client->sendAsyncRequest($request1)
->then(function ($response) {
return $response->withStatus(523);
})
->wait()->getStatusCode() . PHP_EOL;
@Ocramius
Copy link

Try:

<?php
require __DIR__ . "/vendor/autoload.php";
use Amp\Promise;
$client = new Http\Adapter\Artax\Client;
$request1 = new GuzzleHttp\Psr7\Request("GET", "http://example.com/");
var_dump(
    $client->sendAsyncRequest($request1)
        ->then(function ($response) {
            return $response->getBody()->__toString();
        })
        ->wait()

@kelunik
Copy link
Author

kelunik commented Jan 23, 2018

Apart from a missing );, yeah.

PHP Fatal error:  Uncaught Http\Client\Exception\TransferException: Bad reponse returned in /home/kelunik/GitHub/php-http/artax-adapter/src/Internal/Promise.php:50

But just looked at the interface, seems like it doesn't have to behave like that and we could fix it?

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