public function modifyRequest()

in alibabacloud-gateway-sls/php/src/Client.php [70:148]


    public function modifyRequest($context, $attributeMap){
        $request = $context->request;
        $hostMap = [];
        if (!Utils::isUnset($request->hostMap)) {
            $hostMap = $request->hostMap;
        }
        $project = @$hostMap["project"];
        $config = $context->configuration;
        $credential = $request->credential;
        $credentialModel = $credential->getCredential();
        $accessKeyId = $credentialModel->accessKeyId;
        $accessKeySecret = $credentialModel->accessKeySecret;
        $securityToken = $credentialModel->securityToken;
        if (!Utils::empty_($securityToken)) {
            $request->headers["x-acs-security-token"] = $securityToken;
        }
        $signatureVersion = Utils::defaultString($request->signatureVersion, "v1");
        $finalCompressType = $this->getFinalRequestCompressType($request->action, $request->headers);
        $contentHash = "";
        // get body bytes
        $bodyBytes = null;
        if (!Utils::isUnset($request->body)) {
            if (StringUtil::equals($request->reqBodyType, "json") || StringUtil::equals($request->reqBodyType, "formData")) {
                $request->headers["content-type"] = "application/json";
                $bodyStr = Utils::toJSONString($request->body);
                $bodyBytes = Utils::toBytes($bodyStr);
            }
            else if (StringUtil::equals($request->reqBodyType, "binary")) {
                // content-type: application/octet-stream
                $bodyBytes = Utils::assertAsBytes($request->body);
            }
        }
        // get body raw size
        $bodyRawSize = "0";
        $rawSizeRef = @$request->headers["x-log-bodyrawsize"];
        // for php bug, Argument #1 ($value) could not be passed by reference
        if (!Utils::isUnset($rawSizeRef)) {
            $bodyRawSize = $rawSizeRef;
        }
        else if (!Utils::isUnset($request->body)) {
            $bodyRawSize = "" . (string) (DarabonbaGatewaySlsUtilClient::bytesLength($bodyBytes)) . "";
        }
        // compress if needed, and set body and hash
        if (!Utils::isUnset($request->body)) {
            if (!Utils::empty_($finalCompressType)) {
                $compressed = DarabonbaGatewaySlsUtilClient::compress($bodyBytes, $finalCompressType);
                $bodyBytes = $compressed;
            }
            $contentHash = $this->makeContentHash($bodyBytes, $signatureVersion);
            $request->stream = $bodyBytes;
        }
        $host = $this->getHost($config->network, $project, $config->endpoint);
        $request->headers = Tea::merge([
            "accept" => "application/json",
            "host" => $host,
            "user-agent" => $request->userAgent,
            "x-log-apiversion" => "0.6.0"
        ], $request->headers);
        $request->headers["x-log-bodyrawsize"] = $bodyRawSize;
        $this->setDefaultAcceptEncoding($request->action, $request->headers);
        $this->buildRequest($context);
        // move param in path to query
        if (StringUtil::equals($signatureVersion, "v4")) {
            if (Utils::empty_($contentHash)) {
                $contentHash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
            }
            $date = $this->getDateISO8601();
            $request->headers["x-log-date"] = $date;
            $request->headers["x-log-content-sha256"] = $contentHash;
            $request->headers["authorization"] = $this->getAuthorizationV4($context, $date, $contentHash, $accessKeyId, $accessKeySecret);
            return null;
        }
        if (!Utils::empty_($accessKeyId)) {
            $request->headers["x-log-signaturemethod"] = "hmac-sha256";
        }
        $request->headers["date"] = Utils::getDateUTCString();
        $request->headers["content-md5"] = $contentHash;
        $request->headers["authorization"] = $this->getAuthorization($request->pathname, $request->method, $request->query, $request->headers, $accessKeyId, $accessKeySecret);
    }