/** * Gets the redirect url of the provided response * @param HttpRequest $request The performed request * @param HttpResponse $response The received response * @return zibo\library\Url The URL of the redirect location * @throws zibo\library\network\http\exception\HttpException when the provided response has no Location header */ public function getRedirectUrl(HttpRequest $request, HttpResponse $response) { $location = $response->getHeader('Location'); if (!$location) { throw new HttpException('Could not get the redirect URL from the response: no Location header set'); } if (!String::looksLikeUrl($location)) { if ($location[0] == '/') { $base = $request->getUrl()->getBaseUrl(); } else { $base = $request->getUrl()->getBasePath(); } $location = rtrim($base, '/') . '/' . ltrim($location, '/'); } return new Url($location); }
/** * @dataProvider providerParseResponse */ public function testParseResponse($responseCode, $headers, $response) { $response = new HttpResponse($response); $this->assertEquals($responseCode, $response->getResponseCode()); $this->assertEquals($headers, $response->getHeaders()); }