@param string $method
@param string $uri
@param array  $headers
@param mixed  $body
@param string $version
@param int    $retries
@param array  $options

@return Request
436697
protected function buildRequest(
        $method,
        $uri,
        array $headers,
        $body = null,
        $version = '1.1',
        $retries = 0,
        array $options = [],
        $serviceKey,
        $requestKey
    ) {
        return new Request($method, $uri, $headers, $body, (string)$version, $retries, $options, $serviceKey, $requestKey);
    }
557365
public function send($method, $uri, $body = null, array $query = [], array $headers = [], array $options = [])
    {
        $options = $this->enhanceOptions($body, $query, $headers, $options);

        try {
            $this->lastResponse = $this->client->request($method, $uri, $options);
        } catch (GuzzleException $e) {
            throw new ApiException($e->getMessage(), $e->getCode());
        }

        $this->validateResponse($this->lastResponse);

        return $this->lastResponse;
    }
883865
protected function _doRequest($method, $uri, $options)
    {
        return $this->httpClient->request($method, $uri, $options);
    }
1233581
public static function createRequest($method, $path, $body = [], array $headers = [])
    {
        return new Request($method, $path, $body, $headers);
    }
891582
protected function makeHttpRequest($url, $method, $headers, $body = null) {
    $request_headers = array_merge($headers, self::$api_version_header);

    $result = $this->doHttpRequest($url,
                                   $method,
                                   $request_headers,
                                   $body);

    if ($result === false) {
      return false;
    }

    return [
      'status_code' => $result['status_code'],
      'headers' => $result['headers'],
      'body' => $result['body'],
    ];
  }
944963
public function request(string $uri, string $method = null, array $query = null, $body = null, array $headers = null):ResponseInterface{
		$method    = \strtoupper($method ?? 'GET');
		$headers   = Psr7\normalize_request_headers($headers);
		$request   = new Request($method, Psr7\merge_query($uri, $query ?? []));

		if(\in_array($method, ['DELETE', 'PATCH', 'POST', 'PUT'], true) && $body !== null){

			if(\is_array($body) || \is_object($body)){

				if(!isset($headers['Content-type'])){
					$headers['Content-type'] = 'application/x-www-form-urlencoded';
				}

				if($headers['Content-type'] === 'application/x-www-form-urlencoded'){
					$body = \http_build_query($body, '', '&', \PHP_QUERY_RFC1738);
				}
				elseif($headers['Content-type'] === 'application/json'){
					$body = \json_encode($body);
				}
				else{
					$body = null; // @todo
				}

			}

			$request = $request->withBody(Psr17\create_stream((string)$body));
		}

		foreach($headers as $header => $value){
			$request = $request->withAddedHeader($header, $value);
		}

		return $this->sendRequest($request);
	}
632572
public function invoke($uri, $method, array $headers = [])
    {
        $client   = new Client();
        $res      = $client->createRequest(strtoupper($method), url('/') . '/' . $uri, array_merge($headers, $this->getHeaders()));
        $response = $res->send();
        $types    = $response->getHeader('Content-Type')->toArray();
        $body     = $response->getBody(true);
        foreach ($types as $type) {
            if ($type == 'application/json' && function_exists('json_decode') and is_string($body)) {
                return json_decode($body);
            }
        }

        return $body;
    }
1154221
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
    {
        $request = parent::write($method, $uri, $http_ver, $headers, $body);
        $this->log("\n\n" . $request);
        return $request;
    }
100611
public function createRequest($method = 'GET', $uri = null, $headers = null, $body = null, array $options = array())
    {
        $uri = '{+base_path}/' . ltrim($uri, '/');
        return parent::createRequest($method, $uri, $headers, $body, $options);
    }
909282
public function request($method = self::REQUEST_POST, $resource, array $params = [], array $headers = [])
    {
        $signature = $this->createSignature($resource);
        $method = strtoupper($method);

        $options = [
            'headers' => array_merge($headers, [
                'X-Auth-Key' => $this->key,
                'X-Auth-Workspace' => $this->workspace,
                'X-Auth-Signature' => $signature,
                'Content-Type' => 'application/json; charset=utf-8',
                'Accept' => 'application/json'
            ])
        ];

        /**
         * If POST and data is not an url then send data in body as json string
         */
        if ($method === self::REQUEST_POST && isset($params['data']) && !self::isUrl($params['data']))
        {
            if (is_string($params['data']))
            {
                $params['data'] = self::stringToArray($params['data']);
            }

            if ($params['data'])
            {
                $options[\GuzzleHttp\RequestOptions::JSON] = $params['data'];
                unset($params['data']);
            }
        }

        $options[\GuzzleHttp\RequestOptions::QUERY] = $params;
        return $this->handleRequest($method, $resource, $options);
    }
1110228
public function doRequest($uri, $method = 'GET', $headers = array(), $body = NULL) {

    $in = NULL;
    if (!empty($body)) {
      // For whatever reason, CURL seems to want POST request data to be
      // a string, not a file handle. So we adjust. PUT, on the other hand,
      // needs to be in a file handle.
      if ($method == 'POST') {
        $in = $body;
      }
      else {
        // First we turn our body into a temp-backed buffer.
        $in = fopen('php://temp', 'wr', FALSE);
        fwrite($in, $body, strlen($body));
        rewind($in);
      }
    }
    return $this->handleDoRequest($uri, $method, $headers, $in);
    //return $this->handleDoRequest($uri, $method, $headers, $body);

  }
117473
private function processMethod($method, array $options, array $headers, array $body = [])
    {
        if ($method === 'get') {
            if ($body !== []) {
                throw new \Exception('Issuing a GET request with a body');
            }
            $options[CURLOPT_HTTPGET] = 1;
        } elseif ($method === 'post') {
            $data_string = json_encode($body);

            $options[CURLOPT_POST] = 1;
            $options[CURLOPT_POSTFIELDS] = $data_string;

            array_push($headers, 'Content-Type: application/json');
            array_push($headers, 'Content-Length: ' . strlen($data_string));
        } else {
            throw new \Exception('Unrecognized method ' . strtoupper($method));
        }

        return [$options, $headers];
    }
728180
public function requestAsync($method, $url, $body = [], $query = [], $headers = [])
    {
        if (!empty($body)) {
            $body = encode($body);
            $headers['Content-Type'] = 'application/json';
        } else {
            $body = null;
        }

        $headers = array_merge($this->global_headers, $headers);

        return $this->client->requestAsync($method, $url, [
            'query'   => $query,
            'body'    => $body,
            'headers' => $headers,
        ]);
    }
1026909
public static function request($method, $url, $query_data = null, $body = null, array $headers = array(), array $options = array())
    {
        $method = strtoupper($method);

        $_options = array(
            'method' => $method,
            'user_agent' => 'pake '.pakeApp::VERSION,
            'ignore_errors' => true,
        );

        $parsed_url = parse_url($url);

        $proxy_var_name = null;

        if ($parsed_url['scheme'] == 'http') {
            $proxy_var_name = 'http_proxy';
        } elseif ($parsed_url['scheme'] == 'https') {
            if (isset($_SERVER['https_proxy'])) {
                $proxy_var_name = 'https_proxy';
            } elseif (isset($_SERVER['HTTPS_PROXY'])) {
                $proxy_var_name = 'HTTPS_PROXY';
            }
        }

        if (null !== $proxy_var_name) {
            if (isset($_SERVER[$proxy_var_name])) {
                $parsed_proxy_str = parse_url($_SERVER[$proxy_var_name]);

                if (is_array($parsed_proxy_str) and
                    $parsed_proxy_str['scheme'] == 'http' and
                    isset($parsed_proxy_str['host']) and
                    isset($parsed_proxy_str['port'])
                ) {
                    $_options['proxy'] = 'tcp://'.$parsed_proxy_str['host'].':'.$parsed_proxy_str['port'];
                    $_options['request_fulluri'] = true;
                    pake_echo_comment('(using proxy: '.$parsed_proxy_str['host'].':'.$parsed_proxy_str['port'].')');
                } else {
                    pake_echo_error('"'.$proxy_var_name.'" environment variable is set to the wrong value. expecting http://host:port');
                }
            }
        }

        if (null !== $body) {
            if (is_array($body)) {
                $body = http_build_query($body);
            }

            $_options['content'] = $body;
        }

        if (count($headers) > 0) {
            $_options['header'] = implode("\r\n", $headers)."\r\n";
        }

        $options = array_merge($_options, $options);

        if (null !== $query_data) {
            if (is_array($query_data)) {
                $query_data = http_build_query($query_data);
            }

            $url .= '?'.$query_data;
        }

        $context = stream_context_create(array('http' => $options));

        pake_echo_action('HTTP '.$method, $url);
        $stream = @fopen($url, 'r', false, $context);

        if (false === $stream) {
            $err = error_get_last();
            throw new pakeException('HTTP request failed: '.$err['message']);
        }

        $meta = stream_get_meta_data($stream);
        $response = stream_get_contents($stream);

        fclose($stream);

        $status = $meta['wrapper_data'][0];
        $code = substr($status, 9, 3);

        if ($code > 400)
            throw new pakeException('http request returned: '.$status);

        pake_echo_action('…', 'got '.strlen($response).' bytes');

        return $response;
    }
365744
public function post($uri, $body = null, array $options = [])
    {
        return $this->request(self::REQUEST_METHOD_POST, $uri, $body, $options);
    }
809097
private function requestHub($method, $uri, $options)
    {
        try {
            if ($this->getAsync()) {
                return $this->client->requestAsync($method, $uri, $options);
            }

            return $this->client->request($method, $uri, $options);
        } catch (ConnectException $e) {
            if ($options['retries'] > 0) {
                --$options['retries'];

                return $this->requestHub($method, $uri, $options);
            }

            throw new ConnectException($e->getMessage(), $e->getRequest(), null, $e->getHandlerContext());
        }
    }
132425
public function request($method, $uri, array $parameters = [], array $options = [])
    {
        $parameters['key'] = $this->apiKey;
        $options['query'] = $parameters;

        $uri = $this->apiUrl.$uri.'/json';

        $this->log($method, $uri, $options);
        $response = $this->httpClient->request($method, $uri, $options);

        $result = $this->decoder->decode($response);

        if (!isset($result['status'])) {
            throw new ClientErrorException('Missing return status');
        }

        if (!in_array($result['status'], [
                'OK',
                'ZERO_RESULTS',
            ], true)) {
            throw new ClientErrorException(sprintf('Invalid return status "%s"', $result['status']));
        }

        return $result;
    }