Skip to content

Commit

Permalink
chore: add query mode header
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean O'Brien committed Nov 12, 2024
1 parent 9e4be60 commit 7453477
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changes/nextrelease/query-mode-header.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "enhancement",
"category": "",
"description": "Adds opt-in header for query-compatible services"
}
]
16 changes: 16 additions & 0 deletions src/AwsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/AwsClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class AwsClientTest extends TestCase
{
use UsesServiceTrait;
use TestServiceTrait;

private function getApiProvider()
{
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 7453477

Please sign in to comment.