aws-sdk-php: Duplicated scheme "http" in Uri by the S3EndpointMiddleware

Confirm by changing [ ] to [x] below to ensure that it’s a bug:

Describe the bug When the endpoint option is set and path style endpoints are set to true, the S3EndpointMiddleware produces a Uri with both the scheme and the host in the host property of the Uri. This causes issues when the Uri get’s to Guzzle as Guzzle replaces the blank scheme with ‘http’, duplicating ‘http’ in the final Uri.

Version of AWS SDK for PHP? v3.173.0

Version of PHP (php -v)? na

To Reproduce (observed behavior) We encountered this bug while using the sdk configured via the Symfony aws bundle, with the options for path style endpoints set to true and custom endpoints for localstack.

aws:
  S3:
    use_path_style_endpoint: true
    endpoint: http://my-endpoint:123

Expected behavior Here is a failing unit test showing what I thought the expected behavior should be.

    public function testApplyingEndpointWhenEndpointOptionAndPathStyleAreSet()
    {
        $nextHandler = function ($command, Request $request){
            $uri = $request->getUri();
            $this->assertEquals($expectedHost = 'my-endpoint', $uri->getHost());
            $this->assertEquals($expectedScheme = 'http', $uri->getScheme());
        };
        $command = new Command('CreateBucket', ['Bucket' => 'abc']);
        $middleware = new S3EndpointMiddleware( $nextHandler, 'us-west-2', [
            'endpoint' => 'http://my-endpoint:123',
            'path_style' => true
        ]);
        $requestUri = new Uri('http://my-endpoint:123');
        $request = new Request('PUT',$requestUri);
        $middleware($command, $request);
    }

Additional context I’m not the most familiar with the implications of path style endpoints. I’ve read a bit about the plan for them to be deprecated. So sorry in advance if there is something I am missing and this is not an issue.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 20
  • Comments: 25 (10 by maintainers)

Most upvoted comments

@SamRemis I can confirm that downgrading to 3.172.4 works for me.

@NickJorens and @stevepop, Thank you so much for your help in confirming the issue is resolved

@stevepop, depending on how you’re integrating the SDK with your project, the fix earlier may not have worked due to the version number. The fix I pushed was in 3.173.2

@stevepop Thank you, I will look into that too and try to get another urgent fix out

@aldenw This is certainly an issue, and thanks for bringing it to my attention. I’ll take a look right away