Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 7 additions & 12 deletions src/Api/Serializer/JsonRpcSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use Aws\Api\Service;
use Aws\CommandInterface;
use Aws\EndpointV2\EndpointProviderV2;
use Aws\EndpointV2\EndpointV2SerializerTrait;
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\RequestInterface;

Expand Down Expand Up @@ -56,8 +56,7 @@ public function __construct(
*/
public function __invoke(
CommandInterface $command,
$endpointProvider = null,
$clientArgs = null
$endpoint = null
)
{
$operationName = $command->getName();
Expand All @@ -68,15 +67,11 @@ public function __invoke(
'Content-Type' => $this->contentType
];

if ($endpointProvider instanceof EndpointProviderV2) {
$this->setRequestOptions(
$endpointProvider,
$command,
$operation,
$commandArgs,
$clientArgs,
$headers
);
if ($endpoint instanceof RulesetEndpoint) {
$this->applyHeaders($endpoint, $headers);
$resolvedUrl = $endpoint->getUrl();
$this->applyScheme($resolvedUrl);
$this->endpoint = $resolvedUrl;
}

return new Request(
Expand Down
18 changes: 7 additions & 11 deletions src/Api/Serializer/QuerySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Aws\CommandInterface;
use Aws\EndpointV2\EndpointProviderV2;
use Aws\EndpointV2\EndpointV2SerializerTrait;
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\RequestInterface;

Expand Down Expand Up @@ -42,8 +43,7 @@ public function __construct(
*/
public function __invoke(
CommandInterface $command,
$endpointProvider = null,
$clientArgs = null
$endpoint = null
)
{
$operation = $this->api->getOperation($command->getName());
Expand All @@ -67,15 +67,11 @@ public function __invoke(
'Content-Type' => 'application/x-www-form-urlencoded'
];

if ($endpointProvider instanceof EndpointProviderV2) {
$this->setRequestOptions(
$endpointProvider,
$command,
$operation,
$commandArgs,
$clientArgs,
$headers
);
if ($endpoint instanceof RulesetEndpoint) {
$this->applyHeaders($endpoint, $headers);
$resolvedUrl = $endpoint->getUrl();
$this->applyScheme($resolvedUrl);
$this->endpoint = $resolvedUrl;
}

return new Request(
Expand Down
26 changes: 11 additions & 15 deletions src/Api/Serializer/RestSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Aws\CommandInterface;
use Aws\EndpointV2\EndpointProviderV2;
use Aws\EndpointV2\EndpointV2SerializerTrait;
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
Expand Down Expand Up @@ -49,33 +50,28 @@ public function __construct(Service $api, $endpoint)
*/
public function __invoke(
CommandInterface $command,
$endpointProvider = null,
$clientArgs = null
$endpoint = null
)
{
$operation = $this->api->getOperation($command->getName());
$commandArgs = $command->toArray();
$opts = $this->serialize($operation, $commandArgs);
$headers = isset($opts['headers']) ? $opts['headers'] : [];

if ($endpointProvider instanceof EndpointProviderV2) {
$this->setRequestOptions(
$endpointProvider,
$command,
$operation,
$commandArgs,
$clientArgs,
$headers
);
$this->endpoint = new Uri($this->endpoint);
$headers = $opts['headers'] ?? [];

if ($endpoint instanceof RulesetEndpoint) {
$this->applyHeaders($endpoint, $headers);
$resolvedUrl = $endpoint->getUrl();
$this->applyScheme($resolvedUrl);
$this->endpoint = new Uri($resolvedUrl);
}

$uri = $this->buildEndpoint($operation, $commandArgs, $opts);

return new Request(
$operation['http']['method'],
$uri,
$headers,
isset($opts['body']) ? $opts['body'] : null
$opts['body'] ?? null
);
}

Expand Down
25 changes: 11 additions & 14 deletions src/AwsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Aws\Api\Service;
use Aws\EndpointDiscovery\EndpointDiscoveryMiddleware;
use Aws\EndpointV2\EndpointProviderV2;
use Aws\EndpointV2\EndpointV2Middleware;
use Aws\Exception\AwsException;
use Aws\Signature\SignatureProvider;
use GuzzleHttp\Psr7\Uri;
Expand Down Expand Up @@ -240,7 +241,9 @@ public function __construct(array $args)
$this->loadAliases();
$this->addStreamRequestPayload();
$this->addRecursionDetection();
$this->addRequestBuilder();
if ($this->isUseEndpointV2()) {
$this->addEndpointV2Middleware();
}

if (isset($args['with_resolved'])) {
$args['with_resolved']($config);
Expand Down Expand Up @@ -499,24 +502,18 @@ private function addRecursionDetection()
);
}

/**
* Adds the `builder` middleware such that a client's endpoint
* provider and endpoint resolution arguments can be passed.
*/
private function addRequestBuilder()
private function addEndpointV2Middleware()
{
$handlerList = $this->getHandlerList();
$serializer = $this->serializer;
$endpointProvider = $this->endpointProvider;
$list = $this->getHandlerList();
$endpointArgs = $this->getEndpointProviderArgs();

$handlerList->prependBuild(
Middleware::requestBuilder(
$serializer,
$endpointProvider,
$list->prependBuild(
EndpointV2Middleware::wrap(
$this->endpointProvider,
$this->getApi(),
$endpointArgs
),
'builderV2'
'endpointV2_middleware'
);
}

Expand Down
6 changes: 6 additions & 0 deletions src/ClientResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class ClientResolver
],
'serializer' => [
'default' => [__CLASS__, '_default_serializer'],
'fn' => [__CLASS__, '_apply_serializer'],
'internal' => true,
'type' => 'value',
'valid' => ['callable'],
Expand Down Expand Up @@ -834,6 +835,11 @@ public static function _default_use_dual_stack_endpoint(array &$args) {
return UseDualStackConfigProvider::defaultProvider($args);
}

public static function _apply_serializer($value, array &$args, HandlerList $list)
{
$list->prependBuild(Middleware::requestBuilder($value), 'builder');
}

public static function _apply_debug($value, array &$args, HandlerList $list)
{
if ($value !== false) {
Expand Down
Loading