Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __invoke(
// Content-Type must not be set
if ($operation['input'] !== null) {
$body = $this->serialize($operation->getInput(), $commandArgs);
$headers['Content-Length'] = strlen($body);
$headers['Content-Length'] = (string) strlen($body);
} else {
unset($headers['Content-Type']);
}
Expand Down
2 changes: 1 addition & 1 deletion aws/aws-sdk-php/src/Api/Serializer/JsonRpcSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __invoke(
$headers = [
'X-Amz-Target' => $this->api->getMetadata('targetPrefix') . '.' . $operationName,
'Content-Type' => $this->contentType,
'Content-Length' => strlen($body)
'Content-Length' => (string) strlen($body)
];

if ($endpoint instanceof RulesetEndpoint) {
Expand Down
2 changes: 1 addition & 1 deletion aws/aws-sdk-php/src/Api/Serializer/QuerySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __invoke(
}
$body = http_build_query($body, '', '&', PHP_QUERY_RFC3986);
$headers = [
'Content-Length' => strlen($body),
'Content-Length' => (string) strlen($body),
'Content-Type' => 'application/x-www-form-urlencoded'
];
$requestUri = $operation['http']['requestUri'] ?? null;
Expand Down
2 changes: 1 addition & 1 deletion aws/aws-sdk-php/src/Api/Serializer/RestJsonSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function payload(StructureShape $member, array|string $value, array &$
{
$opts['headers']['Content-Type'] = $this->contentType;
$body = $this->jsonFormatter->build($member, $value);
$opts['headers']['Content-Length'] = strlen($body);
$opts['headers']['Content-Length'] = (string) strlen($body);
$opts['body'] = $body;
}
}
66 changes: 60 additions & 6 deletions aws/aws-sdk-php/src/Api/Serializer/RestSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,18 @@ private function applyPayload(StructureShape $input, $name, array $args, array &

$body = $args[$name];
if (!$m['streaming'] && is_string($body)) {
$opts['headers']['Content-Length'] = strlen($body);
$opts['headers']['Content-Length'] = (string) strlen($body);
}

// Streaming bodies or payloads that are strings are
// always just a stream of data.
$opts['body'] = Psr7\Utils::streamFor($body);
$stream = Psr7\Utils::streamFor($body);
// User-owned resource which should be detached instead of closed
// during garbage-collection
if (is_resource($body)) {
$stream = \Aws\detach_on_close_stream($stream);
}
$opts['body'] = $stream;
return;
}

Expand All @@ -173,20 +179,36 @@ private function applyPayload(StructureShape $input, $name, array $args, array &

private function applyHeader($name, Shape $member, $value, array &$opts)
{
// Handle lists by recursively applying header logic to each element
if ($value === null) {
return;
}

// Handle lists by applying header logic to each element
if ($member instanceof ListShape) {
if (!is_array($value)) {
throw new \InvalidArgumentException('Header values must be scalar or an array of scalars.');
}

$listMember = $member->getMember();
$headerValues = [];

foreach ($value as $listValue) {
if ($listValue === null) {
throw new \InvalidArgumentException('Header values must be scalar or an array of scalars.');
}

$tempOpts = ['headers' => []];
$this->applyHeader('temp', $listMember, $listValue, $tempOpts);
if (!array_key_exists('temp', $tempOpts['headers'])) {
throw new \InvalidArgumentException('Header values must be scalar or an array of scalars.');
}

$convertedValue = $tempOpts['headers']['temp'];
$headerValues[] = $convertedValue;
}

$value = $headerValues;
} elseif (!is_null($value)) {
} else {
switch ($member->getType()) {
case 'timestamp':
$timestampFormat = $member['timestampFormat'] ?? 'rfc822';
Expand All @@ -208,7 +230,7 @@ private function applyHeader($name, Shape $member, $value, array &$opts)
$value = base64_encode($value);
}

$opts['headers'][$member['locationName'] ?: $name] = $value;
$opts['headers'][$member['locationName'] ?: $name] = self::prepareHeaderValue($value);
}

/**
Expand All @@ -218,8 +240,40 @@ private function applyHeaderMap($name, Shape $member, array $value, array &$opts
{
$prefix = $member['locationName'];
foreach ($value as $k => $v) {
$opts['headers'][$prefix . $k] = $v;
if ($v === null) {
continue;
}

$opts['headers'][$prefix . $k] = self::prepareHeaderValue($v);
}
}

/**
* @return string|string[]
*/
private static function prepareHeaderValue($value)
{
if (is_scalar($value)) {
return (string) $value;
}

if (is_array($value)) {
if ($value === []) {
return '';
}

foreach ($value as $key => $item) {
if (!is_scalar($item)) {
throw new \InvalidArgumentException('Header values must be scalar or an array of scalars.');
}

$value[$key] = (string) $item;
}

return $value;
}

throw new \InvalidArgumentException('Header values must be scalar or an array of scalars.');
}

private function applyQuery($name, Shape $member, $value, array &$opts)
Expand Down
2 changes: 1 addition & 1 deletion aws/aws-sdk-php/src/Api/Serializer/RestXmlSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function payload(StructureShape $member, array $value, array &$opts)
{
$opts['headers']['Content-Type'] = 'application/xml';
$body = $this->getXmlBody($member, $value);
$opts['headers']['Content-Length'] = strlen($body);
$opts['headers']['Content-Length'] = (string) strlen($body);
$opts['body'] = $body;
}

Expand Down
9 changes: 5 additions & 4 deletions aws/aws-sdk-php/src/AwsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ private function addQueryModeHeader(): void
{
$list = $this->getHandlerList();
$list->appendBuild(
Middleware::mapRequest(function (RequestInterface $r) {
Middleware::mapRequest(static function (RequestInterface $r) {
return $r->withHeader(
'x-amzn-query-mode',
"true"
Expand Down Expand Up @@ -657,11 +657,12 @@ private function addUserAgentMiddleware($args)
*/
private function addEventStreamHttpFlagMiddleware(): void
{
$api = $this->getApi();
$this->getHandlerList()
-> appendInit(
function (callable $handler) {
return function (CommandInterface $command, $request = null) use ($handler) {
$operation = $this->getApi()->getOperation($command->getName());
static function (callable $handler) use ($api) {
return static function (CommandInterface $command, $request = null) use ($handler, $api) {
$operation = $api->getOperation($command->getName());
$output = $operation->getOutput();
foreach ($output->getMembers() as $memberProps) {
if (!empty($memberProps['eventstream'])) {
Expand Down
70 changes: 43 additions & 27 deletions aws/aws-sdk-php/src/ClientResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
use Aws\EndpointDiscovery\ConfigurationInterface;
use Aws\EndpointDiscovery\ConfigurationProvider;
use Aws\EndpointV2\EndpointDefinitionProvider;
use Aws\EndpointV2\EndpointProviderV2;
use Aws\Exception\AwsException;
use Aws\Exception\InvalidRegionException;
use Aws\Retry\ConfigurationInterface as RetryConfigInterface;
use Aws\Retry\ConfigurationProvider as RetryConfigProvider;
use Aws\Retry\V3\OptIn as NewRetriesOptIn;
use Aws\Retry\V3\RetryMiddleware as RetryV3Middleware;
use Aws\Signature\SignatureProvider;
use Aws\Token\Token;
use Aws\Token\TokenInterface;
Expand Down Expand Up @@ -547,28 +550,42 @@ private function throwRequired(array $args)
public static function _apply_retries($value, array &$args, HandlerList $list)
{
// A value of 0 for the config option disables retries
if ($value) {
$config = RetryConfigProvider::unwrap($value);
if (!$value) {
return;
}

if ($config->getMode() === 'legacy') {
// # of retries is 1 less than # of attempts
$decider = RetryMiddleware::createDefaultDecider(
$config->getMaxAttempts() - 1
);
$list->appendSign(
Middleware::retry($decider, null, $args['stats']['retries']),
'retry'
);
} else {
$list->appendSign(
RetryMiddlewareV2::wrap(
$config,
['collect_stats' => $args['stats']['retries']]
),
'retry'
);
}
$config = RetryConfigProvider::unwrap($value);

if ($config->getMode() === 'legacy') {
// # of retries is 1 less than # of attempts
$decider = RetryMiddleware::createDefaultDecider(
$config->getMaxAttempts() - 1
);
$list->appendSign(
Middleware::retry($decider, null, $args['stats']['retries']),
'retry'
);
return;
}

if (NewRetriesOptIn::isEnabled()) {
$list->appendSign(
RetryV3Middleware::wrap($config, [
'collect_stats' => $args['stats']['retries'],
'service' => $args['service'],
]),
'retry'
);
return;
}

$list->appendSign(
RetryMiddlewareV2::wrap(
$config,
['collect_stats' => $args['stats']['retries']]
),
'retry'
);
}

public static function _apply_defaults($value, array &$args, HandlerList $list)
Expand Down Expand Up @@ -791,7 +808,7 @@ public static function _apply_api_provider(callable $value, array &$args)
public static function _apply_endpoint_provider($value, array &$args)
{
if (!isset($args['endpoint'])) {
if ($value instanceof \Aws\EndpointV2\EndpointProviderV2) {
if ($value instanceof EndpointProviderV2) {
$options = self::getEndpointProviderOptions($args);
$value = PartitionEndpointProvider::defaultProvider($options)
->getPartition($args['region'], $args['service']);
Expand Down Expand Up @@ -1112,14 +1129,13 @@ public static function _default_endpoint_provider(array $args)
if (self::isValidService($serviceName)
&& self::isValidApiVersion($serviceName, $apiVersion)
) {
$ruleset = EndpointDefinitionProvider::getEndpointRuleset(
$partitions = EndpointDefinitionProvider::getPartitions();
$parsed = EndpointDefinitionProvider::getParsedRuleset(
$service->getServiceName(),
$service->getApiVersion()
);
return new \Aws\EndpointV2\EndpointProviderV2(
$ruleset,
EndpointDefinitionProvider::getPartitions()
$service->getApiVersion(),
$partitions
);
return new EndpointProviderV2($parsed, $partitions);
}
$options = self::getEndpointProviderOptions($args);
return PartitionEndpointProvider::defaultProvider($options)
Expand Down
Loading