Neos\Flow\Http\Client\Browser::request PHP Method

request() public method

If a Location header was given and the status code is of response type 3xx (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, 14.30 Location)
public request ( string | Uri $uri, string $method = 'GET', array $arguments = [], array $files = [], array $server = [], string $content = null ) : Response
$uri string | Neos\Flow\Http\Uri
$method string Request method, for example "GET"
$arguments array Arguments to send in the request body
$files array
$server array
$content string
return Neos\Flow\Http\Response The HTTP response
    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;
    }

Usage Example

 /**
  * @test
  * @expectedException \Neos\Flow\Http\Client\InfiniteRedirectionException
  */
 public function browserHaltsOnExceedingMaximumRedirections()
 {
     $requestEngine = $this->createMock(Client\RequestEngineInterface::class);
     for ($i = 0; $i <= 10; $i++) {
         $response = new Http\Response();
         $response->setHeader('Location', 'http://localhost/this/willLead/you/knowhere/' . $i);
         $response->setStatus(301);
         $requestEngine->expects($this->at($i))->method('sendRequest')->will($this->returnValue($response));
     }
     $this->browser->setRequestEngine($requestEngine);
     $this->browser->request('http://localhost/some/initialRequest');
 }
All Usage Examples Of Neos\Flow\Http\Client\Browser::request