@param array|null $server
@param array|null $query
@param array|null $body
@param array|null $cookies
@param array|null $files

@return ServerRequestInterface
339928
public static function createServer(
        array $server = null,
        array $query = null,
        array $body = null,
        array $cookies = null,
        array $files = null
    ): ServerRequestInterface {
        $server = static::normalizeServer($server ?: $_SERVER);
        $files = static::normalizeFiles($files ?: $_FILES);

        $method = self::getMethod($server);
        $headers = self::getHeaders($server);

        if (!isset($server['HTTPS'])) {
            $server['HTTPS'] = 'off';
        }

        if (
            $server['HTTPS'] === 'off' &&
            isset($headers['X-Forwarded-Proto']) &&
            $headers['X-Forwarded-Proto'] === 'https'
        ) {
            $server['HTTPS'] = 'on';
        }

        $uri = Uri::fromArray($server);

        $protocol = self::getProtocol($server);

        if ($cookies === null && isset($headers['Cookie'])) {
            $cookies = self::parseCookieHeader($headers['Cookie']);
        }

        return new ServerRequest($method, $uri, $headers, 'php://input', $protocol, $server, $cookies ?: $_COOKIE,
            $query ?: $_GET, $body ?: $_POST, $files);
    }
89893
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
	{
		if (($this->override || !$request->getParsedBody())
			&& \in_array($request->getMethod(), $this->methods, true)
		) {
			$contentType = \trim($request->getHeaderLine('Content-Type'));

			$parser = null;
			foreach ($this->parsers as $k => $v) {
				if (\stripos($k, $contentType) === 0) {
					$parser = $v;
					break;
				}
			}

			if ($parser !== null) {
				try {
					$data = $parser($request->getBody(), $contentType);

					if (isset($data['body'])) {
						$request = $request->withParsedBody($data['body']);
					}

					if (isset($data['files'])) {
						$request = $request->withUploadedFiles($data['files']);
					}
				} catch (\Exception $exception) {
					return Factory::response(400);
				}
			}
		}

		return $handler->handle($request);
	}
1339523
public function execute(string $query, array $parameters): CollectionInterface
    {
        $numServers = count($this->availableServers) - 1;

        for ($i = 0; $i <= $numServers; $i++) {
            // always get the first available server
            $server = $this->availableServers[0];

            // Move the selected server to the end of the stack
            $this->availableServers[] = array_shift($this->availableServers);

            $options = array_merge($this->httpOptions, [
                'base_uri' => sprintf('%s://%s', $this->protocol, $server),
                'json'     => [
                    'stmt' => $query,
                    'args' => $parameters,
                ],
            ]);

            try {
                $response     = $this->httpClient->request('POST', '/_sql', $options);
                $responseBody = json_decode((string)$response->getBody(), true);

                return new Collection(
                    $responseBody['rows'],
                    $responseBody['cols'],
                    $responseBody['duration'],
                    $responseBody['rowcount']
                );
            } catch (ConnectException $exception) {
                // Catch it before the BadResponseException but do nothing.
                continue;
            } catch (BadResponseException $exception) {
                $body = (string)$exception->getResponse()->getBody();
                $json = json_decode($body, true);

                if ($json === null && json_last_error() !== JSON_ERROR_NONE) {
                    throw new RuntimeException(sprintf('Server returned non-JSON response: %s', $body), 0, $exception);
                }

                $errorCode    = $json['error']['code'];
                $errorMessage = $json['error']['message'];

                throw new RuntimeException($errorMessage, $errorCode, $exception);
            }
        }

        throw new ConnectException(
            sprintf('No more servers available, exception from last server: %s', $exception->getMessage()),
            $exception->getRequest(),
            $exception
        );
    }
1103026
public function createServerRequest(array $server, $method = null, $uri = null)
    {
        $method = $method ?: $server['REQUEST_METHOD'];
        if (is_string($uri)) {
            $uri = (new UriFactory())->createUri($uri);
        }

        $uri = $uri ?: (new UriFactory())->createUriFromServer($server);

        $body = (new StreamFactory())->createInputStream();
        $headers = Headers::createFromServer($server);
        $param = $server;
        $cookies = self::parseCookies($headers->get('Cookie', []));
        $version = self::getProtocolVersion($server);

        $request = new ServerRequest($method, $uri, $body, $headers, $param, $cookies, null, $version);

        if ($method === 'POST' &&
            in_array($request->getHeaderObject()->getContentType(), ['application/x-www-form-urlencoded', 'multipart/form-data'])
        ) {
            $request = $request->withParsedBody($_POST);
        }

        return $request;
    }
63893
public function initialize(array $query, array $post, array $cookie, array $server, array $files, array $env, $content = null)
    {
        $this->query = new Collection($query);
        $this->post = new Collection($post);
        $this->put = new Collection([]);
        $this->patch = new Collection([]);
        $this->delete = new Collection([]);
        $this->env = new Collection($env);
        $this->header = new Header($server);
        $this->server = new Collection($server);
        $this->cookie = new Collection($cookie);

        $this->files = new Files($files);
        $this->content = $content;
        $this->method = null;
        $this->setClientIPs();
        $this->setPath();
        $this->setUnsupportedMethodsIfExists();

        return $this;
    }
89982
public function post(string $query, ?string $body = null): ResponseInterface
    {
        $options = [
            'headers' => $this->getAuthorizationHeader(),
        ];

        if ($body) {
            $options['body'] = $body;
        }

        return $this->client->request('post', $this->buildQuery($query), $options);
    }
522091
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
		$method = $method ?? 'GET';
		$params = $this->requestParams($path, $params ?? [], $body ?? []);

		if($method === 'POST'){
			$body   = $params;
			$params = [];
		}

#		return parent::request('', $params, $method, $body, $headers);

		$request = $this->requestFactory
			->createRequest($method, Psr7\merge_query($this->apiURL, $params));

		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
			$request = $request->withAddedHeader($header, $value);
		}

		if($method === 'POST'){
			$request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
			$body    = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));
			$request = $request->withBody($body);
		}

		return $this->http->sendRequest($request);
	}
487891
public static function request($resource, $method, array $data = null, array $files = null)
    {
        if (!strpos($resource, '://')) {
            if (!strpos($resource, '.')) {
                $resource .= '.json';
            }
            $resource = self::API_URL . $resource;
        }

        $hasCURLFile = class_exists('CURLFile', false) && defined('CURLOPT_SAFE_UPLOAD');

        foreach ((array) $data as $key => $val) {
            if ($val === null) {
                unset($data[$key]);
            } elseif ($files && !$hasCURLFile && substr($val, 0, 1) === '@') {
                throw new TwitterException('Due to limitation of cURL it is not possible to send message starting with @ and upload file at the same time in PHP < 5.5');
            }
        }

        foreach ((array) $files as $key => $file) {
            if (!is_file($file)) {
                throw new TwitterException("Cannot read the file $file. Check if file exists on disk and check its permissions.");
            }
            $data[$key] = $hasCURLFile ? new \CURLFile($file) : '@' . $file;
        }

        $request = Twitter_OAuthRequest::from_consumer_and_token(self::$consumer, self::$token, $method, $resource, $files ? [] : $data);
        $request->sign_request(new Twitter_OAuthSignatureMethod_HMAC_SHA1, self::$consumer, self::$token);

        $options = [
                CURLOPT_HEADER => false,
                CURLOPT_RETURNTRANSFER => true,
            ] + ($method === 'POST' ? [
                CURLOPT_POST => true,
                CURLOPT_POSTFIELDS => $files ? $data : $request->to_postdata(),
                CURLOPT_URL => $files ? $request->to_url() : $request->get_normalized_http_url(),
            ] : [
                CURLOPT_URL => $request->to_url(),
            ]) + self::$httpOptions;

        if ($method === 'POST' && $hasCURLFile) {
            $options[CURLOPT_SAFE_UPLOAD] = true;
        }

        $curl = curl_init();
        curl_setopt_array($curl, $options);
        $result = curl_exec($curl);
        if (curl_errno($curl)) {
            throw new TwitterException('Server error: ' . curl_error($curl));
        }

        $payload = defined('JSON_BIGINT_AS_STRING')
            ? @json_decode($result, false, 128, JSON_BIGINT_AS_STRING)
            : @json_decode($result); // intentionally @

        if ($payload === false) {
            throw new TwitterException('Invalid server response');
        }

        $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        if ($code >= 400) {
            throw new TwitterException(isset($payload->errors[0]->message)
                ? $payload->errors[0]->message
                : "Server error #$code with answer $result",
                $code
            );
        }

        return $payload;
    }
220325
public static function createServerRequest(
		ServerInfo $serverInfo,
		Input $input,
		CookieHandler $cookieHandler
	):ServerRequestInterface {
		$uri = new Uri($serverInfo->getRequestUri());
		$headers = new RequestHeaders($serverInfo->getHttpHeadersArray());

		$request = (new ServerRequest(
			$serverInfo->getRequestMethod(),
			$uri,
			$headers,
			$serverInfo,
			$input,
			$cookieHandler
		))
		->withProtocolVersion($serverInfo->getServerProtocolVersion())
		->withBody($input->getStream());

		return $request;
	}
465921
public function buildPostRequest($uri, $query, $param, $headers = [], $isAsync = false)
    {
        $query_param = array_merge(['xh' => $this->stu_id], $query);
        $post = [
            'query' => $query_param,
            'headers' => $headers,
            'form_params' => $param,
        ];

        //If opened cookie cache
        if ($this->cacheCookie) {
            $post['cookies'] = $this->getCookie();
        }

        //If use getAll(), use the Async request.
        return $isAsync
            ? $this->client->postAsync($uri, $post)
            : $this->client->post($uri, $post);
    }
1009248
public function writeOne(string $query, array $bindings = [], array $files = [], array $settings = []): bool
    {
        if (!$query instanceof Query) {
            $query = $this->createQuery($this->getServer(), $query, $bindings, $files, $settings);
        }
        
        $result = $this->getTransport()->write([$query], 1);
        
        return $result[0][0];
    }
851236
public static function create($type, $uri, $method = 'GET', $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
    {
        self::configureFactory($type);

        return \call_user_func_array([self::getClass($type), 'create'], [$uri, $method, $parameters, $cookies, $files, $server, $content]);
    }
1343863
public function createServerRequest(
        string $method,
        $uri,
        array $serverParams = []
    ): ServerRequestInterface{
        if(!is_string($uri) && !is_subclass_of($uri, UriInterface::class)){
            $class  = UriInterface::class;
            throw new \InvalidArgumentException(
                "Second argument must be of the type string or {$class}, " . gettype($uri) . " given."
            );
        }

        return new ServerRequest(
            $method,
            is_string($uri) ? $this->getUriFactory()->createUri($uri) : $uri,
            $serverParams
        );
    }
313797
public static function capture(
        array $server = null,
        array $post = null,
        array $files = null,
        array $headers = null,
        array $cookies = null
    ) {
        $server  = $server ?? $_SERVER;
        $post    = $post ?? $_POST;
        $cookies = $cookies ?? $_COOKIE;

        $method = $server['REQUEST_METHOD'] ?? 'GET';
        $url    = Url::capture($server);

        $request = new static($method, $url, $post);
        $request->files   = Upload::capture($files);
        $request->headers = Header::capture($headers);
        $request->cookie  = $cookies;

        return $request;
    }
330011
public function request(string $path, array $params = null, string $method = null, $body = null, array $headers = null):ResponseInterface{
		$params = $params ?? [];
		$method = strtoupper($method);
		$token  = $this->storage->getAccessToken($this->serviceName);

		if($token->isExpired()){
			$token = $this->refreshAccessToken($token);
		}

		if(!isset($params['fmt'])){
			$params['fmt'] = 'json';
		}

		if(in_array($method, ['POST', 'PUT', 'DELETE']) && !isset($params['client'])){
			$params['client'] = $this->options->user_agent;
		}

		$headers = array_merge($this->apiHeaders, $headers ?? [], ['Authorization' => 'Bearer '.$token->accessToken]);

		return parent::request(explode('?', $path)[0], $params, $method, $body, $headers);
	}
336355
private function _buildRequest($method, $path, $body = null, $contentType = null)
	{
		// copy default headers
		$headers = $this->_headers;

		// add Content-Type header if provided
		if ($contentType)
			$headers []= new HeaderField('Content-Type', $contentType);

		$request = new Request(
			$method,
			$this->_url->getUrlForRelativePath($path),
			$headers,
			$body
		);

		// pass the request through the filter chain
		foreach($this->_filters as $filter)
		{
			$request = $filter->request($request);
		}

		return $request;
	}
829615
public function post(string $path, array $query = [], array $body = []): ResponseInterface
    {
        return $this->request('POST', $path, $query, $body);
    }