diff --git a/.changes/nextrelease/query-mode-header.json b/.changes/nextrelease/query-mode-header.json new file mode 100644 index 0000000000..9416c37c07 --- /dev/null +++ b/.changes/nextrelease/query-mode-header.json @@ -0,0 +1,7 @@ +[ + { + "type": "enhancement", + "category": "", + "description": "Adds opt-in header for query-compatible services" + } +] \ No newline at end of file diff --git a/src/AwsClient.php b/src/AwsClient.php index 67ea82f4b8..c14257cb9c 100644 --- a/src/AwsClient.php +++ b/src/AwsClient.php @@ -12,6 +12,7 @@ use Aws\Exception\AwsException; use Aws\Signature\SignatureProvider; use GuzzleHttp\Psr7\Uri; +use Psr\Http\Message\RequestInterface; /** * Default AWS client implementation @@ -275,6 +276,7 @@ public function __construct(array $args) if (!is_null($this->api->getMetadata('awsQueryCompatible'))) { $this->addQueryCompatibleInputMiddleware($this->api); + $this->addQueryModeHeader(); } if (isset($args['with_resolved'])) { @@ -524,6 +526,20 @@ private function addQueryCompatibleInputMiddleware(Service $api) ); } + private function addQueryModeHeader() + { + $list = $this->getHandlerList(); + $list->appendBuild( + Middleware::mapRequest(function (RequestInterface $r) { + return $r->withHeader( + 'x-amzn-query-mode', + true + ); + }), + 'x-amzn-query-mode-header' + ); + } + private function addInvocationId() { // Add invocation id to each request diff --git a/tests/AwsClientTest.php b/tests/AwsClientTest.php index 702843d3b1..bcdfc88841 100644 --- a/tests/AwsClientTest.php +++ b/tests/AwsClientTest.php @@ -33,6 +33,7 @@ class AwsClientTest extends TestCase { use UsesServiceTrait; + use TestServiceTrait; private function getApiProvider() { @@ -982,4 +983,17 @@ public function testClientParameterOverridesDefaultAccountIdEndpointModeBuiltIns self::assertEquals($expectedAccountIdEndpointMode, $builtIns['AWS::Auth::AccountIdEndpointMode']); } + + public function testQueryModeHeaderAdded() + { + $service = $this->generateTestService('json', ['awsQueryCompatible' => true]); + $client = $this->generateTestClient($service); + $list = $client->getHandlerList(); + $list->setHandler(new MockHandler([new Result()])); + $list->appendSign(Middleware::tap(function($cmd, $req) { + $this->assertTrue($req->hasHeader('x-amzn-query-mode')); + $this->assertEquals(true, $req->getHeaderLine('x-amzn-query-mode')); + })); + $client->TestOperation(); + } }