Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add query mode header #3025

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'))) {
stobrien89 marked this conversation as resolved.
Show resolved Hide resolved
$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(): void
{
$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(): void
{
$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();
}
}