Skip to content

Exception thrown using the Symfony profiler for Messenger workers #24

Open
@dev-cld

Description

@dev-cld

Hello,

Listening to Symfony Messenger workers raises a BadRequestException from Symfony\Component\HttpFoundation\Request.

It seems to be due to the introduction of a rejection of some characters in the URIs, including backslashes, by the Request class of the HTTPFoundation component:
symfony/http-foundation@32310ff#diff-de5d8eb3f1d6537c947f70e0a4673779312a902c083739f472c709c037bcbc30R370

if (false !== ($i = strpos($uri, '\\')) && $i < strcspn($uri, '?#')) {
    throw new BadRequestException('Invalid URI: A URI cannot contain a backslash.');
}

Backslashes are used by the bundle in the transaction name, which is composed from the class name of the message, and the class name uses backslashes for the namespace:

$transactionName = \get_class($event->getEnvelope()->getMessage());

$transactionName = \get_class($envelope->getMessage());

Then the SymfonyProfiler uses the transaction name in the URI:

$uri = sprintf('http://%s/%s', $kind, $name);

And creates the Request:

$this->request = Request::create($uri, $kind);

I suggest fixing it by replacing the backslashes in the class name with regular slashes:

$transactionName = str_replace('\\', '/', \get_class($event->getEnvelope()->getMessage()));
$transactionName = str_replace('\\', '/', \get_class($envelope->getMessage()));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions