Drupal throwing status code 400 and BadRequestHttpException when using Google Data Saver
Date Published: January 15, 2024
Issue
Visiting some/all pages show "A client error has occurred"
Watchdog log contains errors similar to this:
... Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
The request has both a trusted "FORWARDED" header and a trusted
"X_FORWARDED_FOR" header, conflicting with each other. You should
either configure your proxy to remove one of them, or configure
your project to distrust the offending one. in Symfony\Component
\HttpKernel\HttpKernel->handle() (line XX of /mnt/www/html/
[sitename]/vendor/symfony/http-kernel/HttpKernel.php) ...
This issue has been reproduced with the following steps when a Drupal site exhibits the problem:
Clear Drupal cache
Visit site without the Google Data Saver extension enabled, confirm a page is a HTTP status 200
Enable the Data Saver extension
Clear Drupal cache again
Visit site again; page status code should be a 400 Bad Request (You can see this in the browser inspector)
Affected Applications/Limitations
This issue stems from a combination of:
Having a recent update of Drupal (and the Symfony components)
With the results of the problem potentially ending up cached in Drupal's internal cache for other browsers (regardless of them using the Google Compression proxy or not).