public function request($uri, $method = 'GET', array $arguments = [], array $files = [], array $server = [], $content = null)
{
if (is_string($uri)) {
$uri = new Uri($uri);
}
if (!$uri instanceof Uri) {
throw new \InvalidArgumentException('$uri must be a URI object or a valid string representation of a URI.', 1333443624);
}
$request = Request::create($uri, $method, $arguments, $files, $server);
if ($content !== null) {
$request->setContent($content);
}
$response = $this->sendRequest($request);
$location = $response->getHeader('Location');
if ($this->followRedirects && $location !== null && $response->getStatusCode() >= 300 && $response->getStatusCode() <= 399) {
if (in_array($location, $this->redirectionStack) || count($this->redirectionStack) >= $this->maximumRedirections) {
throw new InfiniteRedirectionException('The Location "' . $location . '" to follow for a redirect will probably result into an infinite loop.', 1350391699);
}
$this->redirectionStack[] = $location;
return $this->request($location);
}
$this->redirectionStack = [];
return $response;
}