Skip to content

Commit

Permalink
No need to move bucket to host for some commands
Browse files Browse the repository at this point in the history
This commit updates the BucketStyleListener to not move the bucket name
to the host header for specific excluded operations. For example, this
makes it possible to iterate over your buckets and call
getBucketLocation on them without worrying about signature version 4
only regions like eu-central-1.
  • Loading branch information
mtdowling committed Nov 17, 2014
1 parent 47e5e31 commit e0b8d72
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Aws/S3/BucketStyleListener.php
Expand Up @@ -24,9 +24,8 @@
*/
class BucketStyleListener implements EventSubscriberInterface
{
/**
* {@inheritdoc}
*/
private static $exclusions = array('GetBucketLocation' => true);

public static function getSubscribedEvents()
{
return array('command.after_prepare' => array('onCommandAfterPrepare', -255));
Expand All @@ -44,6 +43,11 @@ public function onCommandAfterPrepare(Event $event)
$request = $command->getRequest();
$pathStyle = false;

// Skip operations that do not need the bucket moved to the host.
if (isset(self::$exclusions[$command->getName()])) {
return;
}

if ($key = $command['Key']) {
// Modify the command Key to account for the {/Key*} explosion into an array
if (is_array($key)) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Aws/Tests/S3/BucketStyleListenerTest.php
Expand Up @@ -78,4 +78,14 @@ public function testUsesVirtualHostedWhenPossible()
$this->assertEquals('foo.s3.amazonaws.com', $command->getRequest()->getHost());
$this->assertEquals('/Bar', $command->getRequest()->getResource());
}

public function testIgnoresExcludedCommands()
{
$s3 = $this->getServiceBuilder()->get('s3');
$this->setMockResponse($s3, array(new Response(200)));
$command = $s3->getCommand('GetBucketLocation', array('Bucket' => 'foo'));
$command->execute();
$this->assertEquals('s3.amazonaws.com', $command->getRequest()->getHost());
$this->assertEquals('/foo?location', $command->getRequest()->getResource());
}
}

0 comments on commit e0b8d72

Please sign in to comment.