Create a Request object for the given URI

This method will also set the Authorization header for the request

@param string       $method
@param UriInterface $uri

@return RequestInterface
421967
protected function createRequest(string $method, UriInterface $uri): RequestInterface
    {
        $request = $this->requestFactory->createRequest($method, $uri);

        return $request->withHeader('Authorization', $this->createAuthorizationHeader());
    }
127695
public function validateRequest($uri = null, $method = null)
	{
		$endpoint = false;

		if (is_null($uri))
		{
			$uri = "";
		}

		if (is_null($method))
		{
			$method = $_SERVER['REQUEST_METHOD'];
		}

		$parts = parse_url($uri);

		$path = trim($parts['path'], '/');

		if ($path == $this->_request_token_path)
		{
			$this->_provider->isRequestTokenEndpoint(true);
		}
		else if ($path == $this->_access_token_path)
		{
			$header = '';

			if (isset($_SERVER['HTTP_AUTHORIZATION']))
			{
				$header = $_SERVER['HTTP_AUTHORIZATION'];
			}

			// @FIXME: header check is inexact and could give false positives
			// @FIXME: pecl oauth provider doesn't handle x_auth in header
			// @FIXME: api application should convert xauth variables in
			//         header to form/query data as workaround
			// @FIXME: this code is here for future use if/when pecl oauth
			//         provider is fixed

			if (isset($_GET['x_auth_mode'])
				|| isset($_GET['x_auth_username'])
				|| isset($_GET['x_auth_password'])
				|| isset($_POST['x_auth_mode'])
				|| isset($_POST['x_auth_username'])
				|| isset($_POST['x_auth_password'])
				|| !strpos($header, 'x_auth_mode')
				|| !strpos($header, 'x_auth_username')
				|| !strpos($header, 'x_auth_password'))
			{
				$this->_provider->is2LeggedEndpoint(true);
				//$this->_provider->addRequiredParameter ('x_auth_mode');
				//$this->_provider->addRequiredParameter ('x_auth_username');
				//$this->_provider->addRequiredParameter ('x_auth_password');
			}
		}

		try
		{
			$this->_provider->checkOAuthRequest($uri, $method);

			return true;
		}
		catch (OAuthException $E)
		{
		}

		// No attempt was made to sign this, let it pass as such
		if (($this->_provider->consumer_key === null)
			&& ($this->_provider->consumer_secret === null)
			&& ($this->_provider->nonce === null)
			&& ($this->_provider->token === null)
			&& ($this->_provider->token_secret === null)
			&& ($this->_provider->timestamp === null)
			&& ($this->_provider->version === null)
			&& ($this->_provider->signature_method === null)
			&& ($this->_provider->callback === null)
			&& (empty($this->_provider->signature))
		)
		{
			return true;
		}

		// request to authorize path can have token and callback params, but are unsigned
		if ($path == $this->_authorize_path)
		{
			if (($this->_provider->consumer_key === null)
				&& ($this->_provider->consumer_secret === null)
				&& ($this->_provider->nonce === null)
				&& ($this->_provider->token_secret === null)
				&& ($this->_provider->timestamp === null)
				&& ($this->_provider->version === null)
				&& ($this->_provider->signature_method === null)
				&& (empty($this->_provider->signature))
				)
			{
				return true;
			}
		}

		$message = OAuthProvider::reportProblem($E, false);

		// request signed without token is allowed to pass
		if ($message == "oauth_problem=token_rejected")
		{
			if (($this->_provider->consumer_key !== null)
				&& ($this->_provider->consumer_secret !== null)
				&& ($this->_provider->nonce !== null)
				&& (empty($this->_provider->token))
				&& (empty($this->_provider->token_secret))
				&& ($this->_provider->timestamp !== null)
				&& ($this->_provider->version !== null)
				&& ($this->_provider->signature_method !== null)
				&& (!empty($this->_provider->signature))
			)
			{
				return true;
			}
		}

		$status = 401;
		$reason = 'Unauthorized';

		if ($message == "oauth_problem=signature_method_rejected")
		{
			$reason = 'Bad Request';
			$status = 400;
		}
		else if (strpos($message, "oauth_problem=parameter_absent") !== false)
		{
			$reason = 'Bad Request';
			$status = 400;
		}
		else if ($message == "oauth_problem=unknown_problem&code=503")
		{
			$reason = 'Bad Request';
			$status = 400;
		}

		$result['message'] = $message;
		$result['status']  = $status;
		$result['reason']  = $reason;

		return $result;
	}
767508
public function create($method, $url, array $headers = [], $body = null)
    {
        return new Request($method, $url, $headers, $body);
    }
204378
public function createRequest($method, $uri){
        if(!is_string($method)){
            throw new \InvalidArgumentException();
        }else if(!is_string($uri) && !($uri instanceof UriInterface)){
            throw new \InvalidArgumentException();
        }

        if(is_string($uri)){
            $uri    = new Uri($uri);
        }

        return new Request($method, $uri);
    }
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;
    }
661199
private function makeRequest($method, $uri, array $parameters = []) {
    try {
      $response = $this->request($method, $uri, $parameters);
      if (200 != $response->getStatusCode()) {
        throw new DaxkoClientException(sprintf('Got non 200 response code for the uri %s.', $uri));
      }

      if (!$body = $response->getBody()) {
        throw new DaxkoClientException(sprintf('Failed to get response body for the uri %s.', $uri));
      }

      if (!$contents = $body->getContents()) {
        throw new DaxkoClientException(sprintf('Failed to get body contents for the uri: %s.', $uri));
      }

      $object = json_decode($contents);

      // todo remove todo??? @todo Check if object contains data.
      if (isset($object->data)) {
        return $object->data;
      }
      elseif (isset($object->tags)) {
        return $object->tags;
      }

      throw new DaxkoClientException(sprintf('Got unknown body name for method %s.', $method));
    }
    catch (\Exception $e) {
      throw new DaxkoClientException(sprintf('Failed to make a request for uri %s with message %s.', $uri, $e->getMessage()));
    }

  }
1364722
private function request($method, $uri, $body = array())
    {
        try {
            $res = $this->client->request($method, $uri, $body);
            return json_decode($res->getBody());
        } catch(RequestException $e){
            $res = VariableUtil::json2Array(
                json_decode($e->getResponse()->getBody()->getContents())[0]
            );
            /*
             * If the session expired, then we must request a new token with the
             * refresh token.
             */
            if(isset($res['errorCode']) && $res['errorCode'] == 'INVALID_SESSION_ID'){
                $this->refreshToken($method, $uri, $body);
            } else {
                throw new ExternalApiException($e->getMessage(), $e->getCode(), $e);
            }
        }
    }
464585
protected function createRequest($method, $url, $requestHeaders, $requestPayload, $protocolVersion)
    {
        $request = new Request(
            $method,
            $url,
            $requestHeaders,
            $requestPayload,
            $protocolVersion
        );

        return $request;
    }
420408
public function custom($method,$uri,array $headers,$body)
        {
            return $this->prepareRequest($method,$uri,$headers,$body);
        }
1348941
public RequestHeader withMethod(Method method) {
        return new RequestHeader(method, uri, protocol, acceptedResponseProtocols, principal, headers, lowercaseHeaders);
    }
619323
private function createRequest(
        string $method,
        string $path,
        $data = null,
        array $headers = [],
        bool $withAuthorization = true
    ): RequestInterface {
        $uri  = $this->baseUrl.'/'.$path;
        $body = null;

        if (in_array($method, $this->getQueryMethods())) {
            $query = is_array($data) ? http_build_query($data) : $data;

            if (is_string($query) && $query !== '') {
                $uri .= '?'.$query;
            }
        } else {
            $body = is_array($data) ? json_encode($data) : $data;
        }

        $baseHeaders = ['Content-Type' => 'application/json'];

        if ($withAuthorization) {
            $baseHeaders['Authorization'] = $this->getAuthorizationHeader();
        }

        return $this->getMessageFactory()->createRequest($method, $uri, $headers + $baseHeaders, $body);
    }
1373702
protected function createRequest($uri, $method = 'GET')
    {
        $headers = [];
        $version = $this->resolveVersion();
        if (!empty($version)) {
            $headers['Silverstripe-Framework-Version'] = $version;
        }

        return new Request($method, $uri, $headers);
    }
1004999
private static HttpUriRequest createHttpUriRequest(String method, URI uri) {
        switch (method) {
            case "GET":
                return new HttpGet(uri);
            case "HEAD":
                return new HttpHead(uri);
            case "POST":
                return new HttpPost(uri);
            case "PUT":
                return new HttpPut(uri);
            case "PATCH":
                return new HttpPatch(uri);
            case "DELETE":
                return new HttpDelete(uri);
            case "OPTIONS":
                return new HttpOptions(uri);
            case "TRACE":
                return new HttpTrace(uri);
            default:
                throw new IllegalArgumentException("Invalid HTTP method: " + method);
        }
    }
695782
protected function _doRequest($method, $uri, $options)
    {
        // For Guzzle5 we cannot have any options that are not pre-defined,
        // so instead we put it in the config array
        if (isset($options[self::OPT_VIDEO_MANAGER_ID])) {
            $options['config'][self::OPT_VIDEO_MANAGER_ID] = $options[self::OPT_VIDEO_MANAGER_ID];
            unset($options[self::OPT_VIDEO_MANAGER_ID]);
        }

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

        return $this->httpClient->send($request);
    }
275033
final public function withUri(UriInterface $uri, $preserveHost = false): self
    {
        $request = clone $this;
        $request->uri = $uri;

        $uriHost = $uri->getHost();
        if ($preserveHost || $uriHost === '') {
            return $request;
        }

        $uriPort = $uri->getPort();
        if ($uriPort !== null) {
            $uriHost .= ":{$uriPort}";
        }
        return $request->withHeader('Host', $uriHost);
    }
483579
public final function withUri(
       UriInterface $uri,
       $preserveHost = false): RequestInterface
   {
       if (true === $preserveHost
        && !array_key_exists("Host", $this->header)
        && $uri->getHost()) {
           return $this->with("uri", $uri)->withHeader("Host", $uri->getHost());
       }
       return $this->with("uri", $uri);
   }
476915
public function rawRequest($method, $uri, $options)
    {
        try {
            $response = $this->connection->request($method, $uri, $options);
            if ($response->getHeader('Content-Type')[0] == 'text/html') {
                throw new DirectAdminException(sprintf('DirectAdmin API returned text/html to %s %s containing "%s"', $method, $uri, strip_tags($response->getBody()->getContents())));
            }
            $body = $response->getBody()->getContents();
            return Conversion::responseToArray($body);
        } catch (TransferException $exception) {
            // Rethrow anything that causes a network issue
            throw new DirectAdminException(sprintf('%s request to %s failed', $method, $uri), 0, $exception);
        }
    }