diff --git a/src/Zttp.php b/src/Zttp.php index 3c20a58..7ca6d51 100755 --- a/src/Zttp.php +++ b/src/Zttp.php @@ -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); } @@ -247,9 +251,10 @@ class ZttpResponse __call as macroCall; } - function __construct($response) + function __construct($response, $transferStats) { $this->response = $response; + $this->transferStats = $transferStats; } function body() @@ -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; diff --git a/tests/ZttpTest.php b/tests/ZttpTest.php index ada0fd1..c0586e4 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