Executes a curl request.

@param  resource $request
@return Response
488382
public function executeRequest($request)
    {
        $body = curl_exec($request);
        $info = curl_getinfo($request);

        curl_close($request);

        $statusCode = $info['http_code'] === 0 ? 500 : $info['http_code'];

        return new Response((string) $body, $statusCode, []);
    }
178305
protected function doRequest($request)
    {
        if (!$this->firstRequest) {
            $this->initialize($request);
        }
        $this->firstRequest = false;

        $this->applyBindings();
        $this->applyContextualBindings();
        $this->applyInstances();
        $this->applyApplicationHandlers();

        $request = Request::createFromBase($request);
        $response = $this->kernel->handle($request);
        $this->app->make('Illuminate\Contracts\Http\Kernel')->terminate($request, $response);

        return $response;
    }
1050194
public function handle(Request $request)
	{
		// execute response
		$response = $this->next($request);

		// only do this if user wants it expanded
		if (!$expand = $request->getVar('expand', null))
		{
			return $response;
		}

		// normalize keys
		$expandKeys = $this->normalizeExpandKeys($expand);

		// only do on json data
		if (!$response->isJson())
		{
			return $response;
		}

		// get the response content and json decode
		$content = json_decode($response->getContent());

		// make sure to handle array different then a single object
		if (is_array($content))
		{
			// loop through each item in array and covert dates
			foreach ($content as $key => $value)
			{
				$content[$key] = $this->convertExpandKeysInObjects($expandKeys, $value);
			}
		}
		else
		{
			// convert single object dates
			$content = $this->convertExpandKeysInObjects($expandKeys, $content);
		}

		// set the response content to modified content
		$response->setContent(json_encode($content));

		// return response
		return $response;
	}
465230
protected function doRequest(RequestInterface $request)
    {
        $ch = $this->createHandle($request);

        // Execute the request and close the connection.
        $content = curl_exec($ch);

        $error = curl_error($ch);

        if (!$this->getOption('allow_empty_result', false) && !trim((string) $content)) {
            // Error but nothing from cURL? Create our own
            $error = $error ?: 'No HTTP response received';

            throw new HttpRequestException($error, curl_errno($ch));
        }

        if (!$this->getOption('ignore_curl_error', false) && $error !== '') {
            throw new HttpRequestException($error, curl_errno($ch));
        }

        // Get the request information.
        $info = curl_getinfo($ch);

        // Close the connection.
        curl_close($ch);

        return $this->getResponse($content, $info);
    }
447813
private function do_request($curl, $request) {
        $url = $request->getUrl();
        $method = $request->getRequestMethod();
        switch (strtoupper($method)) {
            case 'POST':
                $ret = $curl->post($url, $request->getPostBody());
                break;
            case 'GET':
                $ret = $curl->get($url);
                break;
            case 'HEAD':
                $ret = $curl->head($url);
                break;
            case 'PUT':
                $ret = $curl->put($url);
                break;
            default:
                throw new coding_exception('Unknown request type: ' . $method);
                break;
        }
        return $ret;
    }
759913
private function execute(&$http) {
      $result = curl_exec($http);

      if($result === false) {
        $error_code = curl_errno($http);
        $error_message = curl_error($http);

        curl_close($http);

        throw new CallFailed($error_code, $result, $error_message);
      } else {
        $status = (integer) curl_getinfo($http, CURLINFO_HTTP_CODE);

        curl_close($http);

        switch($status) {
          case 200:
            return $result;
          case 400:
          case 401:
          case 403:
          case 404:
          case 409:
          case 500:
          case 503:
          if(is_string($result) && substr($result, 0, 1) === '{') {
            throw new AppException($status, $result); // Known application exception
          } // if
        } // switch

        throw new CallFailed($status, $result); // Unknown exception
      } // if
    }
882230
public function httpPost(Request $request) : Response
    {
        $response = new Response();
        $response->headers->set('Content-Type', 'application/json');

        $response->setContent(
            $this->sdkEndpoint->index(
                $request->getContent()
            )
        );

        return $response;
    }
578478
public function execute (Request $request)
		{
			$parsed = $this->parseRouteRequest($request);

			$controller = $this->getController($request);

			return $controller->dispatch(
				$parsed['method'],
				$parsed['arguments']
			);
		}
695841
public function execute(Request $request, Response $response)
    {
      // Open curl handler
      $handle = curl_init();

      // Set header callback
      curl_setopt($handle, CURLOPT_HEADERFUNCTION, array(&$response, 'header'));

      // Do not reuse connection
      curl_setopt($handle, CURLOPT_FORBID_REUSE, 1);
      curl_setopt($handle, CURLOPT_FRESH_CONNECT, 1);

      // Clear default "Expect: 100-continue" header
      //curl_setopt($handle, CURLOPT_HTTPHEADER, array('Expect:'));

      // Set custom headers
      if($request->hasHeaders())
      {
        curl_setopt($handle, CURLOPT_HEADER, 0);
        curl_setopt($handle, CURLOPT_HTTPHEADER, $request->getHeaders());
      }

      // Set authentication if needed
      if($request->hasUsername() && $request->hasPassword())
      {
        curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($handle, CURLOPT_USERPWD, $request->getUsername() . ':' . $request->getPassword());
      }

      // Set timeout
      if($request->hasTimeout())
        curl_setopt($handle, CURLOPT_TIMEOUT, $request->getTimeout());

      // Set curl options
      curl_setopt($handle, CURLOPT_URL, $request->getUrl());
      curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);

      curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
      //curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);

      curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1);

      // Get method
      $method = $request->getMethod();

      if(!method_exists($this, strtolower($method)))
        throw new Exception(__METHOD__ . '; Request method "' .$method . '" not supported');

      // Call request method handler
      call_user_func(array($this, strtolower($method)),  $handle, $request, $response);

      // Execute curl request
      curl_exec($handle);

      // Get info
      $info = curl_getinfo($handle);

      // Set info
      $response->setInfo($info);

      // Close curl handler
      if(!is_null($handle) && is_resource($handle))
        curl_close($handle);
    }
1320463
public function handle(Request $request)
	{
		$response = $this->next($request);

		try
		{
			$this->app->get('arguments')->parse();
		}
		catch (UnsupportedCommandException $e)
		{
			$this->app->get('output')->error($e->getMessage());
		}
		catch (UnsupportedTaskException $e)
		{
			$this->app->get('output')->error($e->getMessage());
		}

		return $response;
	}
481099
public function send(Request $request)
    {
        $ch = curl_init($request->getUrl());
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getMethod());
        curl_setopt($ch, CURLOPT_HTTPHEADER, HttpUtil::formatHeadersForCurl($request->getHeaders()));
        if (!is_null($request->getBody())) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getBody());
        }

        curl_setopt_array($ch, $request->getCurlOptions());

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FAILONERROR, false);
        curl_setopt($ch, CURLOPT_HEADER, true);

        list($status, $headers, $body) = HttpUtil::parseResponse(curl_exec($ch));

        return new Response(
            HttpUtil::parseStatus($status),
            HttpUtil::parseHeaders($headers),
            $body,
            curl_getinfo($ch)
        );
    }
214392
public function handle(Request $request)
    {
        $response = new Response();
        $response = $this->executePassiveActions($request, $response);
        $response = $this->executeAction($request, $response);

        if ($response->isClientError() || $response->isServerError()) {
            return $this->handleError($request, $response);
        }

        return $response;
    }
863298
protected function handle($request)
    {
        $headers = [];
        $class = $this->repository()->getClassName();

        $this->authorize($request, $class);
        $entity = $this->hydrateEntity($class, $request->getData());
        $this->validateEntity($entity);
        $this->repository()->getEntityManager()->persist($entity);
        $this->repository()->getEntityManager()->flush();

        if ($entity instanceof JsonApiResource) {
            $headers['Location'] = $this->repository()->linkJsonApiResource($request, $entity);
        }

        $resource = new Item($entity, $this->transformer());
        return $this->response()->resource($request, $resource, RestResponse::HTTP_CREATED, $headers);
    }
1203352
private function _curlConnection($request)
    {
        // create a new curl resource
        $curl = curl_init();
        $method = $request->getRequestMethod();
        $headers = array('Expect:');

        // add existing headers into a flat string format
        foreach ($request->getHeaders() as $header) {
            $headers[] = rtrim($header->__toString());
        }

        // set URL and other appropriate options
        curl_setopt($curl, CURLOPT_URL, $request->getUrl());
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_VERBOSE, false);
        curl_setopt($curl, CURLOPT_TIMEOUT_MS, $this->_timeout * 1000);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, $this->_connectTimeoutMs);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_PROTOCOLS, (CURLPROTO_HTTP | CURLPROTO_HTTPS));
        curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, (CURLPROTO_HTTP | CURLPROTO_HTTPS));
        // Prevents issues with curl timing out much faster than the specified timeout
        curl_setopt($curl, CURLOPT_NOSIGNAL, 1);

        if (isset($this->_ipFamily)) {
            curl_setopt($curl, CURLOPT_IPRESOLVE, $this->_ipFamily);
        }

        // enable proxy support
        if (isset($this->_proxy)) {
            curl_setopt($curl, CURLOPT_PROXY, $this->_proxy);
        }

        // enable http authentication
        if (isset($this->_auth)) {
            curl_setopt($curl, CURLOPT_USERPWD, $this->_auth);
            curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        }

        if ($method == 'PUT' || $method == 'POST') {
            $headers[] = 'Content-Length: ' . strlen($request->getBody());

            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getBody());
        } elseif ($method == 'DELETE') {
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        }

        // add HTTP headers
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

        return $curl;
    }
809071
public function execute($request)
    {
        ob_start();
        $logger          = $GLOBALS['logger'];
        $this->_request  = $request;
        $this->_response = new HttpResponse();
        try {
            WebSessionManager::updateActiveSession();
            foreach ($this->_preProcessors as $preProcessor) {
                $preProcessor->process($this->_request);
            }

            $functionToCall = $this->command->getFunction();
            if (empty($functionToCall) === true) {
                $functionToCall = 'default';
            }

            if (!is_callable(array(&$this,'_'.$functionToCall))) {
                $functionToCall = 'error';
            }

            call_user_func(array(&$this,'_'.$functionToCall), $this->_request);
            foreach ($this->_postProcessors as $postProcessor) {
                $postProcessor->process($this->_response);
            }

            ob_end_clean();
            if (empty($this->_response)) {
                $this->_response = new HttpResponse(); 
            }

            if($this->_response->getEncoding() == null) {
                $responseMode = $this->_request->getParam('mode');
                if ($responseMode === 'ui') {
                    $this->_response->setEncoding('html');
                } else if ($responseMode === 'data') {
                    $this->_response->setEncoding('json');
                }
            }
            $this->_response->send();
        } catch (ServiceException $se) {
            $this->_response = new HttpResponse();
            $response->addHeader('HTTP/1.1 400 Bad Request');
            $this->_response->send();
        } catch(BadResponseException $bre) {
            $renderer = new TwigRenderer('500.html');
            if($renderer->exists()) {
                $this->_response = new HttpResponse('none', $renderer);
            } else 
                $this->_response = new HttpResponse();
            $response->addHeader('HTTP/1.1 500 Internal Server Error');
            $this->_response->send();
        }//end try

    }
17081
protected function executeRequest()
    {
        if (!is_callable('curl_init')) {
            throw new Exception\ServiceReaderException('cURL not found.');
        }

        $options  = 'licenseID='  . urlencode($this->apiKey);
        $options .= '&paramsXML=' . urlencode($this->request->generateXMLRequestString());
        $options .= '&content='   . urlencode($this->request->getTextData());

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $this->getApiEndpoint());
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
        curl_setopt($ch, CURLOPT_POST, 1);
        $response = curl_exec($ch);
        curl_close($ch);

        if (strpos($response, "<Exception>") !== false) {
            preg_match("/<Exception\>(.*)<\/Exception>/mu", $response, $matches);
            throw new Exception\ServiceReaderException($matches[1]);
        }

        return new OpenCalaisResponse($response, $this->request);
    }
976047
public function handle(Request $request)
	{
		// execute response
		$response = $this->next($request);

		// only do on json data
		if (!$response->isJson())
		{
			return $response;
		}

		// get the response content and json decode
		$content = json_decode($response->getContent());

		// get date keys from response options
		$this->dateKeys = array_merge(
			$this->dateKeys,
			$response->getTransformKeys('dates')
		);

		// make sure to handle array different then a single object
		if (is_array($content))
		{
			// loop through each item in array and covert dates
			foreach ($content as $key => $value)
			{
				$content[$key] = $this->convertDateKeysInObjects($value);
			}
		}
		else
		{
			// convert single object dates
			$content = $this->convertDateKeysInObjects($content);
		}

		// set the response content to modified content
		$response->setContent(json_encode($content));

		// return response
		return $response;
	}