Send SNP Request message to server.

@param Request $request

@return Response
@throws \bTd\SNP\Protocol\Message\Response\ErrorResponseException|\Exception
439934
protected function sendRequest(Request $request): Response
    {
        // Set password authentication for request.
        if ($this->password !== null) {
            $request->authenticate($this->password);
        }

        $this->send((string) $request);
        $response = new Response($this->get());
        return $response;

    }
1044107
public function send(Request $request)
    {
        $response     = new GetIndexResponse();
        $httpRequest  = $this->createHttpRequest($request);
        $httpResponse = $this->client->send($httpRequest);
        $json         = $httpResponse->json();

        $response->name   = $request->name;
        $response->nVal   = $json['n_val'];
        $response->schema = $json['schema'];

        return $response;
    }
1156183
protected function sendFailedLoginResponse(Request $request)
    {
        return redirect()->back()
            ->withInput($request->only($this->username(), 'remember'))
            ->withErrors([
                $this->username() => Lang::get('auth.failed'),
            ]);
    }
1305804
public function send(Request $request)
    {
        $response     = new GetSchemaResponse();
        $httpRequest  = $this->createHttpRequest($request);
        $httpResponse = $this->client->send($httpRequest);

        $response->name    = $request->name;
        $response->content = (string) $httpResponse->getBody();

        return $response;
    }
781760
public function send(Request $request)
    {
        $curlOptions = [
            CURLOPT_CUSTOMREQUEST => $request->getMethod(),
            CURLOPT_URL => $request->getUri(),
        ];

        if (\in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'], true)) {
            $curlOptions[CURLOPT_POSTFIELDS] = $request->getBody();
        }

        $response = $this->exec($curlOptions, $request->getHeaders());
        if (!$response->isOkay()) {
            $this->logger->warning(
                \sprintf('REQUEST=%s, RESPONSE=%s', $request, $response)
            );
        }

        return $response;
    }
1314857
public function sendRequest(Request $request)
    {
        if (!extension_loaded('curl')) {
            throw new \TYPO3\Flow\Http\Exception(
                'CurlEngine requires the PHP CURL extension to be installed and loaded.',
                1346319808
            );
        }

        $requestUri = $request->getUri();
        $curlHandle = curl_init((string)$requestUri);

        curl_setopt_array($curlHandle, $this->options);

        // If the content is a stream resource, use cURL's INFILE feature to stream it
        $content = $request->getContent();
        if (is_resource($content)) {
            curl_setopt_array(
                $curlHandle,
                [
                    CURLOPT_INFILE => $content,
                    CURLOPT_INFILESIZE => $request->getHeader('Content-Length'),
                ]
            );
        }

        switch ($request->getMethod()) {
            case 'GET':
                if ($request->getContent()) {
                    // workaround because else the request would implicitly fall into POST:
                    curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'GET');
                    if (!is_resource($content)) {
                        curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $content);
                    }
                }
                break;
            case 'POST':
                curl_setopt($curlHandle, CURLOPT_POST, true);
                if (!is_resource($content)) {
                    $body = $content !== '' ? $content : http_build_query($request->getArguments());
                    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $body);
                }
                break;
            case 'PUT':
                curl_setopt($curlHandle, CURLOPT_PUT, true);
                if (!is_resource($content) && $content !== '') {
                    $inFileHandler = fopen('php://temp', 'r+');
                    fwrite($inFileHandler, $request->getContent());
                    rewind($inFileHandler);
                    curl_setopt_array($curlHandle, [
                        CURLOPT_INFILE => $inFileHandler,
                        CURLOPT_INFILESIZE => strlen($request->getContent()),
                    ]);
                }
                break;
            default:
                curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, $request->getMethod());
        }

        $preparedHeaders = [];
        foreach ($request->getHeaders()->getAll() as $fieldName => $values) {
            foreach ($values as $value) {
                $preparedHeaders[] = $fieldName . ': ' . $value;
            }
        }

        // Send an empty Expect header in order to avoid chunked data transfer (which we can't handle yet).
        // If we don't set this, cURL will set "Expect: 100-continue" for requests larger than 1024 bytes.
        $preparedHeaders[] = 'Expect:';

        // Respect headers set by options
        if (isset($this->options[CURLOPT_HTTPHEADER]) && is_array($this->options[CURLOPT_HTTPHEADER])) {
            $preparedHeaders = array_merge($preparedHeaders, $this->options[CURLOPT_HTTPHEADER]);
        }

        // set CURLOPT_HTTPHEADER only once
        curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $preparedHeaders);

        // curl_setopt($curlHandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP && CURLPROTO_HTTPS);
        // CURLOPT_UPLOAD

        if ($requestUri->getPort() !== null) {
            curl_setopt($curlHandle, CURLOPT_PORT, $requestUri->getPort());
        }

        // CURLOPT_COOKIE

        $curlResult = curl_exec($curlHandle);
        if ($curlResult === false) {
            throw new CurlEngineException(
                'cURL reported error code ' . curl_errno($curlHandle)
                . ' with message "' . curl_error($curlHandle) . '". Last requested URL was "'
                . curl_getinfo($curlHandle, CURLINFO_EFFECTIVE_URL) . '".',
                1338906040
            );
        } elseif (strlen($curlResult) === 0) {
            return false;
        }
        curl_close($curlHandle);

        $response = Response::createFromRaw($curlResult);
        if ($response->getStatusCode() === 100) {
            $response = Response::createFromRaw($response->getContent(), $response);
        }
        return $response;
    }
1003931
public function send(Request $request)
    {
        foreach ($this->cookies as $cookie) {
            $request->addCookie($cookie);
        }

        $response = $this->client->request($request);

        if ($response->getCookies()) {
            $this->cookies = $response->getCookies();
        }

        return $response;
    }
1246983
public function send(Request $request)
    {
        $this->monitor->start($this->metricName, ['service_key' => $request->getServiceKey(), 'request_key' => $request->getRequestKey()]);
        $response = $this->sender->send($request);
        $this->monitor->end($this->metricName, ['response_status' => $response->getStatusCode()]);
        return $response;
    }
731669
public function send(Request $request)
    {
        $httpRequest  = $this->createHttpRequest($request);
        $httpResponse = $this->client->send($httpRequest);
        $code         = $httpResponse->getStatusCode();

        if ( ! isset($this->validResponseCodes[$code])) {
            throw RiakTransportException::unexpectedStatusCode($code);
        }

        $json     = $httpResponse->json();
        $props    = $json['props'];
        $response = $this->createGetResponse($props);

        $response->name = $request->bucket;

        return $response;
    }
97728
private function makeExceptionResponse(Request $request): \Generator
    {
        $status = Status::INTERNAL_SERVER_ERROR;

        try {
            return yield $this->errorHandler->handleError($status, null, $request);
        } catch (\Throwable $exception) {
            // If the error handler throws, fallback to returning the default HTML error page.
            $this->logger->error($exception);

            // The default error handler will never throw, otherwise there's a bug
            return yield self::$defaultErrorHandler->handleError($status, null, $request);
        }
    }
1353315
public function send(Request $request)
    {
        $response     = new PutResponse();
        $httpRequest  = $this->createHttpRequest($request);
        $httpResponse = $this->client->send($httpRequest);
        $code         = $httpResponse->getStatusCode();

        if ( ! isset($this->validResponseCodes[$code])) {
            throw RiakTransportException::unexpectedStatusCode($code);
        }

        return $response;
    }
182851
public function send(Request $request)
    {
        $response     = new PutResponse();
        $httpRequest  = $this->createHttpRequest($request);
        $httpResponse = $this->client->send($httpRequest);
        $code         = $httpResponse->getStatusCode();

        if ( ! isset($this->validResponseCodes[$code])) {
            throw RiakTransportException::unexpectedStatusCode($code);
        }

        if ($code === 204) {
            return $response;
        }

        $json    = $httpResponse->json();
        $context = isset($json['context']) ? $json['context'] : null;
        $value   = $json['value'];
        $type    = $json['type'];

        $response->type    = $type;
        $response->context = $context;
        $response->value   = $this->opConverter->fromArray($type, $value);

        return $response;
    }
231355
protected function doSendRequest(Request $request): Response
    {
        if (!$this->shouldUseGearman()) {
            return $this->locator->getRequestBus()->receiveRequest($request);
        }

        $envelope = new TransportEnvelope($request, 'php');
        $channel = $this->router->forRequest($request);

        try {
            $client = $this->getClient();
            $result = @$client->doNormal($channel, $envelope->toString(), (string)$request->get('request_id'));
            $this->validateReturnCode($client, $channel);
            return TransportEnvelope::fromString($result)->getMessage();
        } catch (\GearmanException $ge) {
            if (isset(self::$reconnectCodes[$ge->getCode()])) {
                $this->destroyClient();
                return $this->locator->getRequestBus()->receiveRequest($request);
            }

            throw $ge;
        } catch (\Throwable $e) {
            throw $e;
        }
    }
488624
public function call(Request $request)
    {
        if($request !== $this->getRequestStack()->getCurrentRequest()){
            $this->getRequestStack()->push($request);
        }

        if(!$request->getRequestFormat(null) && $request->getAcceptableContentTypes()){
            $request->setRequestFormat($request->getFormat($request->getAcceptableContentTypes()[0]));
        }

        $response = $this->getRouter()
                ->find($request)
                ->call($this->getServices());

        if($response instanceof Response){
            return $response;
        }
        return new Response($response);
    }
533351
public function ajaxAddAction(Request $request): Response
    {
        if (!$request->isXmlHttpRequest()) {
            return $this->redirectToAction('index');
        }
        
        $attributeName    = $request->request->get('name');
        $attributeGroupId = (int)$request->request->get('set');
        
        try {
            $attribute = $this->getManager()->createAttribute($attributeName, $attributeGroupId);
            
            return $this->jsonResponse([
                'id' => $attribute->getId(),
            ]);
            
        } catch (\Exception $e) {
            
            return $this->jsonResponse([
                'error' => $e->getMessage(),
            ]);
        }
    }
1002818
public function send(?Request $request = null) {
        $request = self::validateRequest($request);

        $this->
            render($request)->
            prepare($request)->
            send();
    }
1369548
public function sendRequest(Request $request)
    {

        $result = $this->responseFactory->create();
        $client = $this->httpClientFactory->create();

        $apiData = $request->getApiData();
        $apiUrl = $request->getApiUrl();
        $apiKey = $request->getApiKey();
        $requestMethod = $request->getRequestMethod();

        $requestData = $requestMethod !== "GET" ? json_encode($apiData, JSON_UNESCAPED_SLASHES) : null;

        $client->setUri($apiUrl);

        $client->setConfig(['maxredirects' => 0, 'timeout' => 30]);

        $headers =  [
            'User-Agent'            => 'BoltPay/Magento-'.$this->configHelper->getStoreVersion() . '/' . $this->configHelper->getModuleVersion(),
            'X-Bolt-Plugin-Version' => $this->configHelper->getModuleVersion(),
            'Content-Type'          => 'application/json',
            'Content-Length'        => $requestData ? strlen($requestData) : null,
            'X-Api-Key'             => $apiKey,
            'X-Nonce'               => rand(100000000000, 999999999999)
        ] + (array)$request->getHeaders();

        $request->setHeaders($headers);

        $this->bugsnag->registerCallback(function ($report) use ($request) {
            $report->setMetaData([
                'BOLT API REQUEST' => $request->getData()
            ]);
        });

        $client->setHeaders($headers);

        $responseBody = null;

        try {
            $response     = $client->setRawData($requestData, 'application/json')->request($requestMethod);
            $responseBody = $response->getBody();

            $this->bugsnag->registerCallback(function ($report) use ($response) {
                $report->setMetaData([
                    'BOLT API RESPONSE' => [
                        'headers' => $response->getHeaders(),
                        'body'    => $response->getBody(),
                    ]
                ]);
            });

            $this->bugsnag->registerCallback(function ($report) use ($response) {
                $headers = $response->getHeaders();
                $report->setMetaData([
                    'META DATA' => [
                        'bolt_trace_id' => @$headers[ConfigHelper::BOLT_TRACE_ID_HEADER],
                    ]
                ]);
            });
        } catch (\Exception $e) {
            throw new LocalizedException($this->wrapGatewayError($e->getMessage()));
        }

        if ($request->getStatusOnly() && $response) {
            return $response->getStatus();
        }

        if ($responseBody) {
            $resultFromJSON = json_decode($responseBody);
            $jsonError  = $this->handleJsonParseError();
            if ($jsonError != null) {
                $message = __("JSON Parse Error: " . $jsonError);
                throw new LocalizedException($message);
            }

            if ($this->isResponseError($resultFromJSON)) {
                $message = isset($resultFromJSON->errors[0]->message) ? __($resultFromJSON->errors[0]->message) :  __("Bolt API Error Response");
                throw new LocalizedException($message);
            }

            $result->setResponse($resultFromJSON);
        } else {
            throw new LocalizedException(
                __('Something went wrong in the payment gateway.')
            );
        }
        return $result;
    }