private function applyEndpoint()

in src/S3/S3EndpointMiddleware.php [295:342]


    private function applyEndpoint(
        CommandInterface $command,
        RequestInterface $request
    ) {
        $dualStack = isset($command['@use_dual_stack_endpoint'])
            ? $command['@use_dual_stack_endpoint'] : $this->dualStackByDefault;
        if (ArnParser::isArn($command['Bucket'])) {
            $arn = ArnParser::parse($command['Bucket']);
            $outpost = $arn->getService() == 's3-outposts';
            if ($outpost && $dualStack) {
                throw new InvalidArgumentException("Outposts + dualstack is not supported");
            }
            if ($arn instanceof ObjectLambdaAccessPointArn) {
                return $request;
            }
        }
        if ($dualStack) {
            throw new InvalidArgumentException("Custom Endpoint + Dualstack not supported");
        }
        if ($command->getName() == 'WriteGetObjectResponse') {
            $host = "{$command['RequestRoute']}.{$this->endpoint}";
            $uri = $request->getUri();
            return $request = $request->withUri(
                $uri->withHost($host)
                    ->withPath($this->getBucketlessPath(
                        $uri->getPath(),
                        $command
                    ))
            );
        }
        $host = ($this->pathStyleByDefault) ?
            $this->endpoint :
            $this->getBucketStyleHost(
                $command,
                $this->endpoint
            );
        $uri = $request->getUri();
        $scheme = $uri->getScheme();
        if(empty($scheme)){
            $request = $request->withUri(
                $uri->withHost($host)
            );
        } else {
            $request = $request->withUri($uri);
        }

        return $request;
    }