public function _request()

in php/src/OpenSearch.php [71:160]


    public function _request($method, $pathname, $query, $headers, $body, $runtime)
    {
        $runtime->validate();
        $_runtime = [
            'timeouted'      => 'retry',
            'readTimeout'    => $runtime->readTimeout,
            'connectTimeout' => $runtime->connectTimeout,
            'httpProxy'      => $runtime->httpProxy,
            'httpsProxy'     => $runtime->httpsProxy,
            'noProxy'        => $runtime->noProxy,
            'maxIdleConns'   => $runtime->maxIdleConns,
            'retry'          => [
                'retryable'   => $runtime->autoretry,
                'maxAttempts' => Utils::defaultNumber($runtime->maxAttempts, 3),
            ],
            'backoff' => [
                'policy' => Utils::defaultString($runtime->backoffPolicy, 'no'),
                'period' => Utils::defaultNumber($runtime->backoffPeriod, 1),
            ],
            'ignoreSSL' => $runtime->ignoreSSL,
        ];
        $_lastRequest   = null;
        $_lastException = null;
        $_now           = time();
        $_retryTimes    = 0;
        while (Tea::allowRetry($_runtime['retry'], $_retryTimes, $_now)) {
            if ($_retryTimes > 0) {
                $_backoffTime = Tea::getBackoffTime($_runtime['backoff'], $_retryTimes);
                if ($_backoffTime > 0) {
                    Tea::sleep($_backoffTime);
                }
            }
            $_retryTimes = $_retryTimes + 1;

            try {
                $_request           = new Request();
                $accesskeyId        = $this->getAccessKeyId();
                $accessKeySecret    = $this->getAccessKeySecret();
                $_request->protocol = Utils::defaultString($this->_protocol, 'HTTP');
                $_request->method   = $method;
                $_request->pathname = $pathname;
                $_request->headers  = Tea::merge([
                    'user-agent'         => $this->getUserAgent(),
                    'Date'               => Client::getDate(),
                    'host'               => Utils::defaultString($this->_endpoint, 'opensearch-cn-hangzhou.aliyuncs.com'),
                    'X-Opensearch-Nonce' => Utils::getNonce(),
                ], $headers);
                if (!Utils::isUnset($query)) {
                    $_request->query = Utils::stringifyMapValue($query);
                }
                if (!Utils::isUnset($body)) {
                    $reqBody                           = Utils::toJSONString($body);
                    $_request->headers['Content-MD5']  = Client::getContentMD5($reqBody);
                    $_request->headers['Content-Type'] = 'application/json';
                    $_request->body                    = $reqBody;
                }
                $_request->headers['Authorization'] = Client::getSignature($_request, $accesskeyId, $accessKeySecret);
                $_lastRequest                       = $_request;
                $_response                          = Tea::send($_request, $_runtime);
                $objStr                             = Utils::readAsString($_response->body);
                if (Utils::is4xx($_response->statusCode) || Utils::is5xx($_response->statusCode)) {
                    throw new TeaError([
                        'message' => $_response->statusMessage,
                        'data'    => $objStr,
                        'code'    => $_response->statusCode,
                    ]);
                }
                $obj = Utils::parseJSON($objStr);
                $res = Utils::assertAsMap($obj);

                return [
                    'body'    => $res,
                    'headers' => $_response->headers,
                ];
            } catch (\Exception $e) {
                if (!($e instanceof TeaError)) {
                    $e = new TeaError([], $e->getMessage(), $e->getCode(), $e);
                }
                if (Tea::isRetryable($e)) {
                    $_lastException = $e;

                    continue;
                }

                throw $e;
            }
        }

        throw new TeaUnableRetryError($_lastRequest, $_lastException);
    }