Same question as a few years back for Drupal7 - but the offline maintenance page seems a little different in Drupal 8/9/10 - and still a work in progress:
https://www.drupal.org/project/drupal/issues/2720109
We have Cloudflare sitting in front of our Drupal sites - and in order to take advantage of their "AlwaysOnline" feature - we need to alter the response code sent in the event of an error - we need a 504 code.
I want to cater for when the database is unavailable - as this can sometimes happen when upgrading the MySQL server.
I did this in Drupal 7 using:
function MYTHEME_preprocess_maintenance_page(&$variables) {
drupal_add_http_header('Status', '504 Service unavailable (with message)');
}
How do we alter the response code in Drupal 9 when the database connection is down without hacking core?