Fuehrt den uebergebenen Request aus und gibt die empfangene Antwort zurueck.

@param  HttpRequest $request

@return HttpResponse

@throws IOException wenn ein Fehler auftritt
975378
public function send(HttpRequest $request) {
        if (!is_resource($this->hCurl))
            $this->hCurl = curl_init();

        $response = new CurlHttpResponse();
        $options  = $this->prepareCurlOptions($request, $response);

        // CURLOPT_FOLLOWLOCATION funktioniert nur bei deaktiviertem "open_basedir"-Setting
        if (!ini_get('open_basedir')) {
            if ($this->isFollowRedirects()) {
                $options[CURLOPT_FOLLOWLOCATION] = true;
            }
            elseif (isset($options[CURLOPT_FOLLOWLOCATION]) && $options[CURLOPT_FOLLOWLOCATION]) {
                $this->setFollowRedirects(true);
            }
            if ($this->isFollowRedirects()) {
                !isset($options[CURLOPT_MAXREDIRS]) && $options[CURLOPT_MAXREDIRS]=$this->maxRedirects;
            }
        }

        if ($request->getMethod() == 'POST') {
            $options[CURLOPT_POST      ] = true;
            $options[CURLOPT_URL       ] = substr($request->getUrl(), 0, strpos($request->getUrl(), '?'));
            $options[CURLOPT_POSTFIELDS] = strstr($request->getUrl(), '?');
        }
        curl_setopt_array($this->hCurl, $options);

        // Request ausfuehren
        if (curl_exec($this->hCurl) === false) throw new IOException('cURL error '.self::getError($this->hCurl).','.NL.'URL: '.$request->getUrl());
        $status = curl_getinfo($this->hCurl, CURLINFO_HTTP_CODE);
        $response->setStatus($status);

        // ggf. manuellen Redirect ausfuehren (falls "open_basedir" aktiviert ist)
        if (($status==301 || $status==302) && $this->isFollowRedirects() && ini_get('open_basedir')) {
            if ($this->manualRedirects >= $this->maxRedirects) throw new IOException('CURL error: maxRedirects limit exceeded - '.$this->maxRedirects.', URL: '.$request->getUrl());
            $this->manualRedirects++;

            /** @var string $location */
            $location = $response->getHeader('Location');                       // TODO: relative Redirects abfangen
            Logger::log('Performing manual redirect to: '.$location, L_INFO);   // TODO: verschachtelte IOExceptions abfangen
            $request  = new HttpRequest($location);
            $response = $this->send($request);
        }

        return $response;
    }
126546
public function readAction(Request $request)
    {
        $response = $this->convertResourceToPlainText(
            $request->getRequestFormat('xml'),
            $this->mapper->getResource($request->get('id'))
        );

        return new Response($response);
    }
918145
public function execute(Request $request): Response
    {
        $method = $request->getMethod();
        list($resp, $grpcStatus) = $request->getClient()->$method(
            $request->getMessage(),
            $request->getMetadata(),
            $request->getOptions()
        )->wait();

        $headers = new HeaderCollection();

        if (is_null($grpcStatus)) { // in the very bad case even this fails to return
            $status = new Error\Status(\Grpc\STATUS_UNKNOWN, '', $headers);
        } else {
            $metadata = $grpcStatus->metadata;
            foreach ($metadata as $k => $v) {
                if (is_array($v)) {
                    foreach ($v as $v2) {
                        $headers->add($k, $v2);
                    }
                } else {
                    $headers->add($k, $v);
                }
            }
            $status = new Error\Status(intval($grpcStatus->code), strval($grpcStatus->details), $headers);
        }

        if (is_null($resp)) {
            $request->fail($status);
        }

        return $request->succeed($resp, $status);
    }
529518
public function do_request($request)
    {
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_AUTOREFERER, true);

        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_MAXREDIRS, 8);

        $body = $request->body;
        if (is_array($body)) {
            if (isset($headers['Content-Type']) && strpos($request->headers['Content-Type'], 'json') !== false) {
                $body = json_encode($body, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
            } else {
                $hasFiles = false;
                /** @noinspection ForeachSourceInspection */
                foreach ($body as $k => $v) {
                    if (is_string($v) && strlen($v) > 1 && $v[0] === '@' && $this->filesystem->fileExists($v)) {
                        $hasFiles = true;
                        $file = $this->alias->resolve($v);
                        $body[$k] = curl_file_create($file, mime_content_type($file) ?: null, basename($file));
                    } elseif (is_object($v)) {
                        $hasFiles = true;
                    }
                }

                if (!$hasFiles) {
                    $body = http_build_query($body);
                }
            }
        }

        switch ($request->method) {
            case 'GET':
                break;
            case 'POST':
                curl_setopt($curl, CURLOPT_POST, 1);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
                break;
            case 'PATCH':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
                curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
                break;
            case 'PUT':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
                curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
                break;
            case 'DELETE':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
                break;
            case 'HEAD':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'HEAD');
                curl_setopt($curl, CURLOPT_NOBODY, true);
                break;
            case 'OPTIONS':
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'OPTIONS');
                break;
            default:
                throw new NotSupportedException(['`:method` method is not support', 'method' => $request->method]);
                break;
        }

        $timeout = $request->options['timeout'];
        curl_setopt($curl, CURLOPT_URL, $request->url);
        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($curl, CURLOPT_HEADER, 1);

        if ($this->_proxy) {
            $parts = parse_url($this->_proxy);
            $scheme = $parts['scheme'];
            if ($scheme === 'http') {
                curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
            } elseif ($scheme === 'sock4') {
                curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
            } elseif ($scheme === 'sock5') {
                curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
            } else {
                throw new NotSupportedException(['`:scheme` scheme of `:proxy` proxy is unknown', 'scheme' => $scheme, 'proxy' => $this->_proxy]);
            }

            curl_setopt($curl, CURLOPT_PROXYPORT, $parts['port']);
            curl_setopt($curl, CURLOPT_PROXY, $parts['host']);
            if (isset($parts['user'], $parts['pass'])) {
                curl_setopt($curl, CURLOPT_PROXYUSERNAME, $parts['user']);
                curl_setopt($curl, CURLOPT_PROXYPASSWORD, $parts['pass']);
            }
        }

        if (isset($request->options['cafile'])) {
            curl_setopt($curl, CURLOPT_CAINFO, $this->alias->resolve($request->options['cafile']));
        }

        if (!$request->options['verify_peer']) {
            /** @noinspection CurlSslServerSpoofingInspection */
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            /** @noinspection CurlSslServerSpoofingInspection */
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        }

        curl_setopt($curl, CURLOPT_HTTPHEADER, $request->headers);

        $start_time = microtime(true);

        $content = curl_exec($curl);

        $err = curl_errno($curl);
        if ($err === 23 || $err === 61) {
            curl_setopt($curl, CURLOPT_ENCODING, 'none');
            $content = curl_exec($curl);
        }

        /** @noinspection NotOptimalIfConditionsInspection */
        if (($errno = curl_errno($curl)) === CURLE_SSL_CACERT && !isset($options['cafile']) && DIRECTORY_SEPARATOR === '\\') {
            $this->logger->warn('ca.pem file is not exists, you should download from https://curl.haxx.se/ca/cacert.pem', 'httpClient.noCaCert');
            /** @noinspection CurlSslServerSpoofingInspection */
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            /** @noinspection CurlSslServerSpoofingInspection */
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

            $content = curl_exec($curl);
            $errno = curl_error($curl);
        }

        $process_time = round(microtime(true) - $start_time, 3);

        if ($errno) {
            throw new ConnectionException(['connect failed: `:url` :message', 'url' => $request->url, 'message' => curl_error($curl)]);
        }

        $header_length = curl_getinfo($curl, CURLINFO_HEADER_SIZE);

        $response = new Response();

        $response->url = $request->url;
        $response->remote_ip = curl_getinfo($curl, CURLINFO_PRIMARY_IP);
        $response->http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $response->headers = explode("\r\n", substr($content, 0, $header_length - 4));
        $response->process_time = $process_time;
        $response->content_type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
        $response->body = substr($content, $header_length);
        $response->stats = [
            'total_time' => curl_getinfo($curl, CURLINFO_TOTAL_TIME),
            'namelookup_time' => curl_getinfo($curl, CURLINFO_NAMELOOKUP_TIME),
            'connect_time' => curl_getinfo($curl, CURLINFO_CONNECT_TIME),
            'pretransfer_time' => curl_getinfo($curl, CURLINFO_PRETRANSFER_TIME),
            'starttransfer_time' => curl_getinfo($curl, CURLINFO_STARTTRANSFER_TIME)];

        curl_close($curl);

        return $response;
    }
332234
public function makeRequest(Google_HttpRequest $request) {
    // First, check to see if we have a valid cached version.
    $cached = $this->getCachedRequest($request);
    if ($cached !== false) {
      if (Google_CacheParser::mustRevalidate($cached)) {
        $addHeaders = array();
        if ($cached->getResponseHeader('etag')) {
          // [13.3.4] If an entity tag has been provided by the origin server,
          // we must use that entity tag in any cache-conditional request.
          $addHeaders['If-None-Match'] = $cached->getResponseHeader('etag');
        } elseif ($cached->getResponseHeader('date')) {
          $addHeaders['If-Modified-Since'] = $cached->getResponseHeader('date');
        }

        $request->setRequestHeaders($addHeaders);
      } else {
        // No need to revalidate the request, return it directly
        return $cached;
      }
    }

    if (array_key_exists($request->getRequestMethod(),
          self::$ENTITY_HTTP_METHODS)) {
      $request = $this->processEntityRequest($request);
    }

    $ch = curl_init();
    curl_setopt_array($ch, $this->curlParams);
    curl_setopt($ch, CURLOPT_URL, $request->getUrl());
    if ($request->getPostBody()) {
      curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getPostBody());
    }

    $requestHeaders = $request->getRequestHeaders();
    if ($requestHeaders && is_array($requestHeaders)) {
      $parsed = array();
      foreach ($requestHeaders as $k => $v) {
        $parsed[] = "$k: $v";
      }
      curl_setopt($ch, CURLOPT_HTTPHEADER, $parsed);
    }

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getRequestMethod());
    curl_setopt($ch, CURLOPT_USERAGENT, $request->getUserAgent());
    $respData = curl_exec($ch);

    // Retry if certificates are missing.
    if (curl_errno($ch) == CURLE_SSL_CACERT) {
      error_log('SSL certificate problem, verify that the CA cert is OK.'
        . ' Retrying with the CA cert bundle from google-api-php-client.');
      curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacerts.pem');
      $respData = curl_exec($ch);
    }

    $respHeaderSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $respHttpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $curlErrorNum = curl_errno($ch);
    $curlError = curl_error($ch);
    curl_close($ch);
    if ($curlErrorNum != CURLE_OK) {
      throw new Google_IOException("HTTP Error: ($respHttpCode) $curlError");
    }

    // Parse out the raw response into usable bits
    list($responseHeaders, $responseBody) =
          self::parseHttpResponse($respData, $respHeaderSize);

    if ($respHttpCode == 304 && $cached) {
      // If the server responded NOT_MODIFIED, return the cached request.
      if (isset($responseHeaders['connection'])) {
        $hopByHop = array_merge(
          self::$HOP_BY_HOP,
          explode(',', $responseHeaders['connection'])
        );

        $endToEnd = array();
        foreach($hopByHop as $key) {
          if (isset($responseHeaders[$key])) {
            $endToEnd[$key] = $responseHeaders[$key];
          }
        }
        $cached->setResponseHeaders($endToEnd);
      }
      return $cached;
    }

    // Fill in the apiHttpRequest with the response values
    $request->setResponseHttpCode($respHttpCode);
    $request->setResponseHeaders($responseHeaders);
    $request->setResponseBody($responseBody);
    // Store the request in cache (the function checks to see if the request
    // can actually be cached)
    $this->setCachedRequest($request);
    // And finally return it
    return $request;
  }
684744
public function toResponse($request)
    {
        if(! $this->handler && ! is_callable($this->handler)) {
            throw new ErrorException("No handler set");
        }

        $parameters = array_merge(
            [$request, $this->action],
            $this->parameters
        );

        try {
            $payload = call_user_func_array($this->handler, array_values($parameters));
        }
        catch (Exception $e) {
            // We'll assume that if an Exception has an error code 
            // that is explicitly defined, we want to use it as an
            // HTTP error code. if not we'll just let the 
            // Exception handler takes care of it. 
            $code = $e->getCode();

            if (! $this->isValidHttpStatusCode($code)) {
                throw $e;
            }
            
            $this->setStatusCode($code);

            return $e instanceof HasMessageBag 
                ? $this->respondWithMessageBag($e->getMessageBag(), class_basename($e))
                : $this->respondWithError($e->getMessage(), class_basename($e));
        }   
        catch (ValidationException $e) {
            throw $e;
        }

        return $this->handlePayload($payload);
    }
1267870
private function getHttpResponse(RequestInterface $request): ?ResponseInterface
    {
        try {
            return $this->httpClient->send($request);
        } catch (TooManyRedirectsException $tooManyRedirectsException) {
            return $this->httpHistoryContainer->getLastResponse();
        } catch (BadResponseException $badResponseException) {
            $this->badRequestCount++;

            if ($this->isBadRequestLimitReached()) {
                return $badResponseException->getResponse();
            }

            return $this->getHttpResponse($request);
        } catch (HttpConnectException $connectException) {
            throw $connectException;
        } catch (RequestException $requestException) {
            if ($this->isCurlException($requestException)) {
                throw new HttpConnectException(
                    $requestException->getMessage(),
                    $requestException->getRequest(),
                    $requestException->getPrevious()
                );
            }

            $this->badRequestCount++;

            if ($this->isBadRequestLimitReached()) {
                return $requestException->getResponse();
            }

            return $this->getHttpResponse($request);
        }
    }
501509
public function apiSaveForm(HTTPRequest $request)
    {
        // Validate required input data
        if (!isset($this->urlParams['ID'])) {
            $this->jsonError(400);
            return null;
        }

        $data = Convert::json2array($request->getBody());
        if (empty($data)) {
            $this->jsonError(400);
            return null;
        }

        // Inject request body as request vars
        foreach ($data as $key => $value) {
            $request->offsetSet($key, $value);
        }

        // Check security token
        if (!SecurityToken::inst()->checkRequest($request)) {
            $this->jsonError(400);
            return null;
        }

        /** @var BaseElement $element */
        $element = BaseElement::get()->byID($this->urlParams['ID']);
        // Ensure the element can be edited by the current user
        if (!$element || !$element->canEdit()) {
            $this->jsonError(403);
            return null;
        }

        // Remove the pseudo namespaces that were added by the form factory
        $data = $this->removeNamespacesFromFields($data, $element->ID);

        try {
            $updated = false;

            $element->updateFromFormData($data);
            // Check if anything will actually be changed before writing
            if ($element->isChanged()) {
                $element->write();
                // Track changes so we can return to the client
                $updated = true;
            }
        } catch (Exception $ex) {
            Injector::inst()->get(LoggerInterface::class)->debug($ex->getMessage());

            $this->jsonError(500);
            return null;
        }

        $body = Convert::raw2json([
            'status' => 'success',
            'updated' => $updated,
        ]);
        return HTTPResponse::create($body)->addHeader('Content-Type', 'application/json');
    }
954915
public function send(Request $request)
    {
        $httpRequest = $this->createHttpRequest($request);
        $response    = new GetResponse();

        try {
            $httpResponse = $this->client->send($httpRequest);
            $code         = $httpResponse->getStatusCode();
        } catch (RequestException $e) {
            if ($e->getCode() == 404 && $request->notfoundOk) {
                return $response;
            }

            throw $e;
        }

        if ( ! isset($this->validResponseCodes[$code])) {
            throw RiakTransportException::unexpectedStatusCode($code);
        }

        $contentList = $this->getRiakContentList($httpResponse);
        $vClock      = $httpResponse->getHeader('X-Riak-Vclock');

        $response->vClock = $vClock;
        $response->contentList = $contentList;

        return $response;
    }
1151102
public static HttpResponse execute(HttpRequestBase request) throws IOException {

		Assert.notNull(request, "Missing request!");
		HttpClient client = HttpClientBuilder.create().setRedirectStrategy(new DefaultRedirectStrategy()).build();
		return client.execute(request);
	}
743828
public function handle(Request $request) : ResponseInterface
  {
    // Reset current context to root context
    $this->currentContext = $this->rootContext;
    if (!$result = $this->handleContext($request, $this->rootContext, true)) {
      throw new HttpException(404);
    }

    return $result;
  }
980314
public static function copy(HttpRequest $request)
    {
        return new self(
            $request->getHost(),
            $request->getUri(),
            $request->getMethod(),
            $request->getHeaders(),
            $request->getBody()
        );
    }
88475
public function run(HttpRequest $request = null): Response
    {
        if ($request === null) {
            $request = HttpRequest::fromGlobals();
        }

        $this->httpRequest = $request;

        $context = new Context($request->getUri()->getPath(), $request);

        $response = $this->getHttpRouter()->route($context);

        if (!$response instanceof HttpResponse) {
            $response = new HttpResponse($response);
        }

        $this->flushResponse($request, $response);

        $this->httpRequest = null;

        return $response;
    }
211661
public function handle(Request $request) : Response
    {
        try {
            return $this->handleRequest($request);
        } catch (HttpException $e) {
            return $this->handleHttpException($e, $request);
        } catch (\Throwable $e) {
            return $this->handleUncaughtException($e, $request);
        }
    }
665117
public function fromRequest(HttpRequestInterface $request)
    {
        return $this->createRequest(
            $request->getMethod(),
            $request->getUri(),
            $request->getHeaders(),
            JsonRpc\json_decode((string) $request->getBody(), true) ?: []
        );
    }
800963
private function executeRequest(string $request): Response
    {
        $response = $this->transport->executeRequest($this->config['endpoint_uri'], $request);

        return new Response($response);
    }
875365
public function handle(Request $request)
    {
        try {
            $restRequest = new RestRequest($this->config, $request->getMethod(), $request->getUri(), $request->getContent());
            $restResponse = $this->adapter->processRequest($restRequest);
        } catch (\Exception $e) {
            if (true === $this->debugEnabled()) {
                throw $e;
            }
            $restResponse = $this->adapter->handleException($e);
        }
        return new Response($restResponse->getContent(), $restResponse->getStatus(), $restResponse->getHeaders());
    }