diff --git a/src/Zttp.php b/src/Zttp.php index af6b5ca..7fe0380 100755 --- a/src/Zttp.php +++ b/src/Zttp.php @@ -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); @@ -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; diff --git a/tests/ZttpTest.php b/tests/ZttpTest.php index 6928499..e5a3189 100644 --- a/tests/ZttpTest.php +++ b/tests/ZttpTest.php @@ -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