Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We have:
HtmlResponse
+\Drupal\Core\EventSubscriber\HtmlResponseSubscriber
+\Drupal\Core\Render\HtmlResponseAttachmentsProcessor
AjaxResponse
+\Drupal\Core\EventSubscriber\AjaxResponseSubscriber
+\Drupal\Core\Ajax\AjaxResponseAttachmentsProcessor
In both of those cases, the response contains the actual data, but some post-processing is necessary to render the final response.
ResourceResponse
is similar: it contains the actual data, but needs some post-processing (serialization!) to render the final response.
Proposed resolution
- Introduce
ResourceResponseSubscriber
to serializeResourceResponseInterface
objects. - Remove
\Drupal\rest\RequestHandler::renderResponse()
. - Figure out a way for retaining BC:
ResourceInterface
plugins are sadly still allowed to return plainResponse
, because that's how D8.0 shipped. We could do something with request attributes, or response headers, to letResourceResponseSubscriber
also detect resource responses that don't implementResourceResponseInterface
.
Remaining tasks
TBD
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
Wim LeersHah, turns out #2807501: ResourceResponse::$responseData is serialized, but is never used: unserializing it on every Page Cache hit is a huge performance penalty already did this, yay! :)