/** * Dispatch the given request and return the generated HTTP response. * * HINT: This method will transform the response entity into a StringEntity populated with the contents of * the original entity, HTTP headers of the original entity will be preserved. * * NOTE: If you do not specify a host in the URL it will be set to test.me! * * @param HttpRequest $request * @return HttpResponse * * @throws \RuntimeException When the dispatcher did not return an HTTP response and no other exception was thrown. */ public function dispatch(HttpRequest $request) { $uri = $request->getUri(); if (NULL === $uri->getHost()) { $request->setUri($uri->setHost('test.me')->setPort(Http::PORT)); } $dispatcher = $this->container->get(DispatcherInterface::class); $chain = $this->container->get(MiddlewareChain::class); $response = $dispatcher->handleRequest($request, $chain, true); if (!$response instanceof HttpResponse) { $type = is_object($response) ? get_class($response) : gettype($response); throw new \RuntimeException(sprintf('Expecting an HttpResponse object, given %s', $type)); } return $response; }