Build Http Request

@param iHttpRequest $request Request Instance to build
332665
function build(iHttpRequest $request)
    {
        switch (1)
        {
            case ($this->protocol !== null): $request->setProtocol($this->protocol);
            case ($this->method   !== null): $request->setMethod($this->method);
            case ($this->host     !== null): $request->setHost($this->host);
            case ($this->version  !== null): $request->setVersion($this->version);
            case ($this->target   !== null): $request->setTarget($this->target);
            case ($this->headers  !== null): $request->setHeaders($this->headers);
            case ($this->body     !== null): $request->setBody($this->body);
        }
    }
962834
public function buildRequest()
    {
        $request = $this->getPayPalRequest();
        $request->setParameter('TOKEN', $this->getSession()->getVariable('oepaypal-token'));

        return $request;
    }
600130
private function post($request)
    {
        try {
            $responseGuzzle = $this->client->request('post', $this->url, $request->build());
        } catch (ClientException $e) {
            $responseGuzzle = $e->getResponse();
        }

        return $responseGuzzle;
    }
977415
private function buildRequest()
	{
		// template example:
		// -----------------
		// {METHOD} {URI} HTTP-{1.0|1.1}CRLF
		// {headers}CRLF
		// CRLF
		// {message-body}
		$method = 'GET';
		$httpVersion = '1.0';
		$headers = '';
		$body = '';
		$page = ( \array_key_exists('path', $this->url) ) ? $this->url[ 'path' ] : '/';
		$options = \stream_context_get_options( $this->context );

		$httpOptions = [];
		if ( \array_key_exists('http', $options) )
		{
			$httpOptions = $options[ 'http' ];
		}
		// Get method verb.
		if ( \array_key_exists('method', $httpOptions) )
		{
			$method = $httpOptions[ 'method' ];
		}
		// Get content body.
		if ( \array_key_exists('content', $httpOptions) )
		{
			$body = $httpOptions[ 'content' ];
		}
		// Get headers.
		if ( \array_key_exists('header', $httpOptions) )
		{
			$headers = $httpOptions[ 'header' ];
		}
		// Get protocol version.
		if ( \array_key_exists('protocol_version', $httpOptions) )
		{
			$httpVersion = $httpOptions[ 'protocol_version' ];
		}
		// When host header was not set using context for \fopen/\file_get_contents functions,
		// you must manually add the Host: header.
		if ( \strpos(strtolower($headers), 'host:') === FALSE )
		{
			$lineBreak = ( \strlen($headers) > 0 ) ? "\r\n" : '';
			$headers = "host: {$this->url['host']}{$lineBreak}{$headers}";
		}
		if ( \array_key_exists('query', $this->url) )
		{
			$page = $page . '?' . $this->url[ 'query' ];
		}
		// Build the request as a string.
		$request = \sprintf(
			"%s %s HTTP/%s\r\n%s\r\n\r\n%s",
			$method,
			$page,
			$httpVersion,
			$headers,
			$body
		);

		return $request;
	}
1253532
public function handleRequest(IHttpClient $request)
    {
        $signedKey = $this->_azureAdTokenProvider->getAccessToken();
        $request->setHeader(Resources::AUTHENTICATION, "Bearer " . $signedKey->getAccessToken());

        return $request;
    }
1100627
protected function processRequest(IHttpRequest $request) {
        // share request instance
        $this->container->set(
            [HttpRequest::class, IHttpRequest::class], $request
        );

        // boot application and the kernel
        $this->start();

        // notify listeners about an incoming http request
        $this->eventer->dispatch(new IncomingHttpRequestEvent($request));

        // allow listeners to handle the request and provide a valid http response
        $event = new HandleHttpRequestEvent($request);
        $this->eventer->dispatch($event);
        $response = $event->getResponse();

        // in case there is a valid http response
        if ($response instanceof IHttpResponse) {
            // give listeners a chance to modify it
            $this->eventer->dispatch(
                new HttpRequestHandledEvent($request, $response)
            );
        }

        // in case there was a valid http response,
        // return it as the final application result
        if ( ! $response instanceof IHttpResponse) {
            $response = new HttpResponse(
                HttpStatusCode::NOT_FOUND,
                s(
                    'Http request was not handled. ' .
                    'It seems like no one is registered to handle it. ' .
                    'You can solve this by handling the "%s" event and providing ' .
                    'a valid IHttpResponse i.e: $event->setResponse($response)',
                    HandleHttpRequestEvent::class
                )
            );
        }

        return $response;
    }
258648
public function init(HTTPRequest $request)
    {

        if (!$this->isStarted() && $this->requestContainsSessionId($request)) {
            $this->start($request);
        }

        // Funny business detected!
        if (isset($this->data['HTTP_USER_AGENT'])) {
            if ($this->data['HTTP_USER_AGENT'] !== $this->userAgent($request)) {
                $this->clearAll();
                $this->destroy();
                $this->started = false;
                $this->start($request);
            }
        }
    }
69287
private function appendHeaders(RequestInterface $request)
    {
        $headers = $this->auth->getHeaders();
        foreach ($headers as $key => $value) {
            $request = $request->withHeader($key, $value);
        }
        return $request;
    }
416845
public static function build(AbstractRequest $request)
    {
        $name = get_class($request);
        if (!isset(self::$loaded[$name])) {
            self::$loaded[$name] = new CurlHandle();
        } else {
            self::$loaded[$name]->reset();
        }
        self::$loaded[$name]->prepare($request);

        return self::$loaded[$name];
    }
1324128
protected function doRequest($request)
    {
        $slimRequest = $this->convertRequest($request);

        $container = $this->app->getContainer();

        /* @var $slimResponse ResponseInterface */
        $slimResponse = $container->get('response');

        // reset body stream
        $slimResponse = $slimResponse->withBody(new Stream(fopen('php://temp', 'w+')));

        $slimResponse = $this->app->process($slimRequest, $slimResponse);

        return new BrowserKitResponse(
            (string) $slimResponse->getBody(),
            $slimResponse->getStatusCode(),
            $slimResponse->getHeaders()
        );
    }
434621
function buildHTTPGetQuery( $request, $queryParams )
    {
        foreach ( $queryParams as $name => $value )
        {
            if ( is_array( $value ) )
            {
                foreach ( $value as $valueKey => $valuePart )
                {
                    $encodedQueryParams[] = urlencode( $name ) . '=' . urlencode( $valuePart );
                }
            }
            else
            {
                $encodedQueryParams[] = urlencode( $name ) . '=' . urlencode( $value );
            }
        }

        return $this->SearchServerURI . $request . '?' . implode( '&', $encodedQueryParams );
    }
474913
private function createHttpRequest(Request $request)
    {
        // The URL
        $url = ltrim(trim($request->getUrl()), '/');

        // Handle templated URLs
        if ($urlVariables = $request->getUrlVariables())
            $url = (new UriTemplate())->expand($url, $urlVariables);

        // Create the request (we will handle the exceptions)
        $httpRequest = $this->client->createRequest($request->getMethod(), $url, array('exceptions' => false));

        // The message body
        if ($messageBody = $request->getMessageBody()) {
            $httpRequest->setHeader('Content-Type', $messageBody->getContentType());
            if(!is_a($messageBody, 'Finix\Http\MultipartBody')) {
                $httpRequest->setHeader('Content-Length', $messageBody->getContentLength());
                $httpRequest->setBody(Stream::factory($messageBody->getContent()));
            }
            else {
                /** @var \Finix\Http\MultipartBody $messageBody */
                $httpRequest->getBody()->addFile($messageBody->getContent());
            }
        }

        // Accept hal+json response
        if ($this->profile) {
            $accept = 'application/hal+json; profile="' . $this->profile . '"';
        } else {
            $accept = 'application/json';
        }

        //$httpRequest->setHeader('Accept', $accept);

        // Additional headers if specified
        foreach ($request->getHeaders() as $key => $value) {
            $httpRequest->setHeader($key, $value);
        }

        // "verify" the request if needed
        $this->verify($httpRequest);

        return $httpRequest;
    }
598175
public function makeRequest(Google_Http_Request $request)
  {
    // First, check to see if we have a valid cached version.
    $cached = $this->getCachedRequest($request);
    if ($cached !== false && $cached instanceof Google_Http_Request) {
      if (!$this->checkMustRevalidateCachedRequest($cached, $request)) {
        return $cached;
      }
    }

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

    list($responseData, $responseHeaders, $respHttpCode) = $this->executeRequest($request);

    if ($respHttpCode == 304 && $cached) {
      // If the server responded NOT_MODIFIED, return the cached request.
      $this->updateCachedRequest($cached, $responseHeaders);
      return $cached;
    }

    if (!isset($responseHeaders['Date']) && !isset($responseHeaders['date'])) {
      $responseHeaders['date'] = date("r");
    }

    $request->setResponseHttpCode($respHttpCode);
    $request->setResponseHeaders($responseHeaders);
    $request->setResponseBody($responseData);
    // Store the request in cache (the function checks to see if the request
    // can actually be cached)
    $this->setCachedRequest($request);
    return $request;
  }
492551
private function createRequest(Request $request = null): void
    {
        if (!$this->request && is_null($request)) {
            $request = ServerRequest::fromGlobals()
                ->withParsedBody(json_decode(file_get_contents('php://input')));
        }

        $this->container->set(Request::class, $request);
        $this->request = $request;
    }
972707
public function doRequestInProcess($request)
    {
        if ($this->mockedResponse) {
            $response = $this->mockedResponse;
            $this->mockedResponse = null;
            return $response;
        }

        $requestCookie = $request->getCookies();
        $requestServer = $request->getServer();
        $requestFiles = $this->remapFiles($request->getFiles());

        $parseResult = parse_url($request->getUri());
        $uri = $parseResult["path"];
        if (array_key_exists("query", $parseResult)) {
            $uri .= "?" . $parseResult["query"];
        }

        $requestRequestArray = $this->remapRequestParameters($request->getParameters());

        $requestServer['REQUEST_METHOD'] = strtoupper($request->getMethod());
        $requestServer['REQUEST_URI'] = $uri;
        $requestServer['HTTP_HOST'] = $this->domain;
        $requestServer['SERVER_PROTOCOL'] = 'HTTP/1.1';
        $requestServer['SERVER_NAME'] = $this->domain;
        $requestServer['HTTP_CLIENT_IP'] = '127.0.0.1';

        $this->index = $this->uriToIndexMapper->getIndexForUri($uri);

        $phpSelf = str_replace($this->rootFolder, '', $this->index);
        $requestServer['PHP_SELF'] = $phpSelf;

        $env = [
            'headers' => $this->headers,
            'cookie' => $requestCookie,
            'server' => $requestServer,
            'files' => $requestFiles,
            'request' => $requestRequestArray,
        ];

        if (strtoupper($request->getMethod()) == 'GET') {
            $env['get'] = $env['request'];
        } else {
            $env['post'] = $env['request'];
        }

        $requestScript = dirname(dirname(__DIR__)) . '/scripts/request.php';

        $command = PHP_BINARY .
            ' ' . escapeshellarg($requestScript) .
            ' ' . escapeshellarg($this->index) .
            ' ' . escapeshellarg(base64_encode(serialize($env)));

        $process = new Process($command);
        $process->run();
        $rawProcessOutput = $process->getOutput();

        $unserializedResponse = @unserialize(base64_decode($rawProcessOutput));

        if (false === $unserializedResponse) {
            $message = 'Server responded with: ' . $rawProcessOutput;
            throw new ModuleException(\Codeception\Module\WordPress::class, $message);
        }

        $_SERVER = empty($unserializedResponse['server']) ? [] : $unserializedResponse['server'];
        $_FILES = empty($unserializedResponse['files']) ? [] : $unserializedResponse['files'];
        $_REQUEST = empty($unserializedResponse['request']) ? [] : $unserializedResponse['request'];
        $_GET = empty($unserializedResponse['get']) ? [] : $unserializedResponse['get'];
        $_POST = empty($unserializedResponse['post']) ? [] : $unserializedResponse['post'];

        $content = $unserializedResponse['content'];
        $headers = $this->replaceSiteUrlDeep($unserializedResponse['headers'], $this->url);

        $response = new Response($content, $unserializedResponse['status'], $headers);

        return $response;
    }
216793
public function handleRequest(IHttpClient $request)
    {
        foreach ($this->_headers as $key => $value) {
            $headers = $request->getHeaders();
            if (!array_key_exists($key, $headers)) {
                $request->setHeader($key, $value);
            }
        }

        return $request;
    }
1215284
public function buildRequestBody(BaseRequest &$request)
    {
        $params = $request->getParameters();
        $params['SecretId'] = $this->secretId;
        $params['Nonce'] = rand(1, 65535);
        $params['Timestamp'] = time();
        $params['SignatureMethod'] = $this->signatureMethod;
        $host = str_replace(['http://', 'https://'], '', $this->endPoint);
        $plainText = $this->makeSignPlainText($params, $this->requestMethod, $host, $this->requestPath);
        //签名
        if ($this->signatureMethod == self::SIGNATURE_METHOD_HMAC_SHA256) {
            $params['Signature'] = base64_encode(hash_hmac('sha256', $plainText, $this->secretKey, true));
        } elseif ($this->signatureMethod == self::SIGNATURE_METHOD_HMAC_SHA1) {
            $params['Signature'] = base64_encode(hash_hmac('sha1', $plainText, $this->secretKey, true));
        }
        //var_dump($params);exit;
        return $params;
    }