Skip to content

Commit

Permalink
Improve interoperability in headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Jun 1, 2020
1 parent b1a5394 commit 6b91371
Showing 1 changed file with 22 additions and 4 deletions.
Expand Up @@ -290,10 +290,28 @@ public function send(string $body, array $headers, int $delay = 0, ?string $mess
'MessageAttributes' => [],
];

$parameters['MessageAttributes'][self::MESSAGE_ATTRIBUTE_NAME] = new MessageAttributeValue([
'DataType' => 'String',
'StringValue' => \json_encode($headers),
]);
$specialHeaders = [];
foreach ($headers as $name => $value) {
if ($name[0] === '.' || $name === self::MESSAGE_ATTRIBUTE_NAME || \strlen($name) > 256 || \substr($name, -1) === '.' || \substr($name, 0, \strlen('AWS.')) === 'AWS.' || \substr($name, 0, \strlen('Amazon.')) === 'Amazon.' || \preg_match('/([^a-zA-Z0-9_\.-]+|\.\.)/', $name)) {
$specialHeaders[$name] = $value;

continue;
}

$parameters['MessageAttributes'][$name] = new MessageAttributeValue([
'DataType' => 'String',
'StringValue' => $value,
]);
}

if (!empty($specialHeaders)) {
$parameters['MessageAttributes'][self::MESSAGE_ATTRIBUTE_NAME] = new MessageAttributeValue([
'DataType' => 'String',
'StringValue' => \json_encode($specialHeaders),
]);
}

dd($parameters);

if (self::isFifoQueue($this->configuration['queue_name'])) {
$parameters['MessageGroupId'] = null !== $messageGroupId ? $messageGroupId : __METHOD__;
Expand Down

0 comments on commit 6b91371

Please sign in to comment.