Skip to content

Commit

Permalink
Merge pull request #69 from Fyrts/master
Browse files Browse the repository at this point in the history
Add ability to get effective response URI
  • Loading branch information
adamwathan authored Jun 10, 2019
2 parents 46bcae6 + 8047041 commit e4ae7ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Zttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ function send($method, $url, $options)
{
try {
return tap(new ZttpResponse($this->buildClient()->request($method, $url, $this->mergeOptions([
'query' => $this->parseQueryParams($url)
'query' => $this->parseQueryParams($url),
'on_stats' => function (\GuzzleHttp\TransferStats $stats) {
$this->transferStats = $stats;
}
], $options))), function($response) {
$response->cookies = $this->cookies;
$response->transferStats = $this->transferStats;
});
} catch (\GuzzleHttp\Exception\ConnectException $e) {
throw new ConnectionException($e->getMessage(), 0, $e);
Expand Down Expand Up @@ -295,6 +299,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 e4ae7ac

Please sign in to comment.