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 82b220b
Showing 1 changed file with 23 additions and 5 deletions.
Expand Up @@ -203,7 +203,7 @@ private function fetchMessage(): bool
$headers = [];
$attributes = $message->getMessageAttributes();
if (isset($attributes[self::MESSAGE_ATTRIBUTE_NAME]) && 'String' === $attributes[self::MESSAGE_ATTRIBUTE_NAME]->getDataType()) {
$headers = \json_decode($attributes[self::MESSAGE_ATTRIBUTE_NAME]->getStringValue(), true);
$headers = json_decode($attributes[self::MESSAGE_ATTRIBUTE_NAME]->getStringValue(), true);
unset($attributes[self::MESSAGE_ATTRIBUTE_NAME]);
}
foreach ($attributes as $name => $attribute) {
Expand Down 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] || self::MESSAGE_ATTRIBUTE_NAME === $name || \strlen($name) > 256 || '.' === substr($name, -1) || 'AWS.' === substr($name, 0, \strlen('AWS.')) || 'Amazon.' === substr($name, 0, \strlen('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 82b220b

Please sign in to comment.