Consider using EventSubscriber for response events instead of Middleware

Created on 8 March 2021, almost 4 years ago
Updated 20 September 2024, 5 months ago

Problem/Motivation

The module currently uses a middleware but it does not perform any action whatsoever with the request, the very first line of the middleware implementation is calling the kernel handle method.

The event I am initially proposing to use is kernel.terminate which is the one the Automated Cron module uses.

I am raising this first to discuss what is the best approach, once that is agreed we can work on changing the code (which should not be a huge change).

Steps to reproduce

NA

Proposed resolution

Use an EventSubscriber on the Response instead, this way we have access to both the Request and Response objects and can act base on that data.

Remaining tasks

Make the UrlRegistrar an EventSubscriber instead.

User interface changes

None

API changes

None (IMO this is not considered an API change since users are not supposed to be using this middleware in any way)

Data model changes

None

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇧🇷Brazil dungahk Balneário Camboriú

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India Vivek Panicker Kolkata

    I think this is a very valid suggestion and would not interfere with the Drupal Core routing system also.
    We should go ahead with this.
    Kernel.terminate would be a good time to do it since by that time the response would already have been sent, so there wouldn't be any extra processing happening during the request.

  • 🇳🇿New Zealand ericgsmith

    We have to make a BC break anyway to support Drupal 11 - so if anybody wants to action this idea I'm not opposed to it. I will need to create a 2.x branch for it.

Production build 0.71.5 2024