Allow HtmlResponse to use a flexible emitter

Created on 30 September 2015, over 8 years ago
Updated 19 March 2024, 3 months ago

Problem/Motivation

To send a streamed response the HtmlResponse::send() method would need to be overwritten.

However cloning the response is not a good option as any subclasses of MyOwnHtmlResponse with added properties would break that.

Also cloning into a new class is quite error prone.

Proposed resolution

Introduce Drupal\Component\HttpFoundation\ResponseEmitterInterface and Drupal\Component\HttpFoundation\ResponseEmitterTrait based on https://github.com/zendframework/zend-diactoros/blob/master/src/Response....

doing basically:


use Symfony\Component\HttpFoundation\Response;

interface ResponseEmitterInterface
{
    /**
     * Emit a response.
     *
     * @param ResponseInterface $response
     */
    public function emit(ResponseInterface $response);
}

and for the trait

trait ResponseEmitterTrait
{
    /**
     * Send a response.
     */
    public function send() {
        if ($this->responseEmitter) {
          $this->responseEmitter->emit($this);
          return $this;
        }

        parent::send();
        return $this;
    }

  public function getResponseEmitter() {
     return $this->responseEmitter;
  }

  public function setResponseEmitter(ResponseEmitterInterface $response_emitter) {
    $this->responseEmitter = $response_emitter;
  }

}

and


class HtmlResponse implements ..., ResponseEmitterInterface {
  use ResponseEmitterTrait;
  // ...
}

and thats it.

Remaining tasks

- Do it
- Write (unit) tests

API changes

- API addition for the Interface

Why this should be an RC target

Soft-Blocker for #2469431: BigPipe for auth users: first send+render the cheap parts of the page, then the expensive parts β†’

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
Request processingΒ  β†’

Last updated about 10 hours ago

No maintainer
Created by

πŸ‡©πŸ‡ͺGermany Fabianx

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

Production build 0.69.0 2024