Problem/Motivation
While working on #2737719: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method, I noticed that responses to DELETE
requests correctly have status 204, correctly have no body, but incorrectly have a Content-Type
header, and it's even set tot he completely nonsensical text/html; charset=UTF-8
. See https://tools.ietf.org/html/rfc2616#section-10.2.5 and #2737719-94: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method.
The root cause: \Symfony\Component\HttpFoundation\Response::prepare()
:
// Fix Content-Type
$charset = $this->charset ?: 'UTF-8';
if (!$headers->has('Content-Type')) {
$headers->set('Content-Type', 'text/html; charset='.$charset);
} elseif (0 === stripos($headers->get('Content-Type'), 'text/') && false === stripos($headers->get('Content-Type'), 'charset')) {
// add the charset
$headers->set('Content-Type', $headers->get('Content-Type').'; charset='.$charset);
}
Nope, this was fixed a long time ago: https://github.com/symfony/symfony/issues/12744 + https://github.com/symfony/symfony/commit/75abd1a451d97f5075128ea10b2598....
The real root cause is PHP: https://bugs.php.net/bug.php?id=70189. This bug exists even in PHP 7.0 (at least in 7.0.12). The fix was committed in March 2016, but it either didn't make it to PHP 7, or it didn't actually solve the problem.
I can reproduce this both with the CLI (when running PHPUnit), and when accessing Drupal via Apache (when performing actual DELETE
requests to an actual Drupal instance).
Proposed resolution
Fix the logic.
Wait for PHP to be fixed, then make the tests more strict.
Remaining tasks
TBD
User interface changes
None.
API changes
None.
Data model changes
None.