Skip to content

Commit

Permalink
Add ability to get effective response URI
Browse files Browse the repository at this point in the history
  • Loading branch information
fyrts committed Apr 2, 2019
1 parent 39f84d0 commit 6ecda16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Zttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ function delete($url, $params = [])
function send($method, $url, $options)
{
try {
return new ZttpResponse($this->buildClient()->request($method, $url, $this->mergeOptions([
$response = $this->buildClient()->request($method, $url, $this->mergeOptions([
'query' => $this->parseQueryParams($url),
], $options)));
'on_stats' => function (\GuzzleHttp\TransferStats $stats) use (&$transferStats) {
$transferStats = $stats;
}
], $options));
return new ZttpResponse($response, $transferStats);
} catch (\GuzzleHttp\Exception\ConnectException $e) {
throw new ConnectionException($e->getMessage(), 0, $e);
}
Expand Down Expand Up @@ -247,9 +251,10 @@ class ZttpResponse
__call as macroCall;
}

function __construct($response)
function __construct($response, $transferStats)
{
$this->response = $response;
$this->transferStats = $transferStats;
}

function body()
Expand Down Expand Up @@ -279,6 +284,11 @@ function status()
return $this->response->getStatusCode();
}

function effectiveURI()
{
return $this->transferStats->getEffectiveUri();
}

function isSuccess()
{
return $this->status() >= 200 && $this->status() < 300;
Expand Down
8 changes: 8 additions & 0 deletions tests/ZttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ function can_use_digest_auth()
$this->assertTrue($response->isOk());
}

/** @test */
function can_retrieve_effective_uri()
{
$response = Zttp::get($this->url('/redirect'));

$this->assertEquals($this->url('/redirected'), $response->effectiveURI());
}

/**
* @test
* @expectedException \Zttp\ConnectionException
Expand Down

0 comments on commit 6ecda16

Please sign in to comment.