diff --git a/core/includes/ajax.inc b/core/includes/ajax.inc index ce56aa7..12e2e69 100644 --- a/core/includes/ajax.inc +++ b/core/includes/ajax.inc @@ -5,6 +5,8 @@ * Functions for use with Drupal's Ajax framework. */ +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; + /** * @defgroup ajax Ajax framework * @{ @@ -326,7 +328,7 @@ function ajax_get_form() { // This is likely a hacking attempt as it never happens under normal // circumstances, so we just do nothing. watchdog('ajax', 'Invalid form POST data.', array(), WATCHDOG_WARNING); - drupal_exit(); + throw new BadRequestHttpException(); } // Since some of the submit handlers are run, redirects need to be disabled. diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 25e9b9a..ca38be8 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Exception\RuntimeException as DependencyInjectionRuntimeException; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Drupal\Core\Language\Language; use Drupal\Core\Lock\DatabaseLockBackend; use Drupal\Core\Lock\LockBackendInterface; diff --git a/core/includes/common.inc b/core/includes/common.inc index e2a28c3..14cb24a 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3,6 +3,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Cache\Cache; use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Yaml\Parser; @@ -725,12 +726,16 @@ function drupal_goto($path = '', array $options = array(), $http_response_code = $url = url($path, $options); - header('Location: ' . $url, TRUE, $http_response_code); + if (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) { + if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') { + module_invoke_all('exit', $url); + } + drupal_session_commit(); + } - // The "Location" header sends a redirect status code to the HTTP daemon. In - // some cases this can be wrong, so we make sure none of the code below the - // drupal_goto() call gets executed upon redirection. - drupal_exit($url); + RedirectResponse::create($url, $http_response_code)->sendHeaders(); + // @todo remove once all page callbacks are converted to new routing system. + exit; } /** @@ -1992,26 +1997,6 @@ function l($text, $path, array $options = array()) { } /** - * Performs end-of-request tasks. - * - * There should rarely be a reason to call exit instead of drupal_exit(); - * - * @param $destination - * If this function is called from drupal_goto(), then this argument - * will be a fully-qualified URL that is the destination of the redirect. - * This should be passed along to hook_exit() implementations. - */ -function drupal_exit($destination = NULL) { - if (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) { - if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') { - module_invoke_all('exit', $destination); - } - drupal_session_commit(); - } - exit; -} - -/** * Forms an associative array from a linear array. * * This function walks through the provided array and constructs an associative diff --git a/core/includes/install.inc b/core/includes/install.inc index 69b421a..87a748e 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -5,6 +5,7 @@ * API functions for installing modules and themes. */ +use Symfony\Component\HttpFoundation\RedirectResponse; use Drupal\Component\Utility\Crypt; use Drupal\Core\Database\Database; use Drupal\Core\DrupalKernel; @@ -861,10 +862,11 @@ function drupal_install_fix_file($file, $mask, $message = TRUE) { */ function install_goto($path) { global $base_url; - include_once DRUPAL_ROOT . '/core/includes/common.inc'; - header('Location: ' . $base_url . '/' . $path); - header('Cache-Control: no-cache'); // Not a permanent redirect. - drupal_exit(); + $headers = array( + // Not a permanent redirect. + 'Cache-Control' => 'no-cache', + ); + RedirectResponse::create($base_url . '/' . $path, 302, $headers)->send(); } /** diff --git a/core/modules/image/image.module b/core/modules/image/image.module index c876bed..8f88fb2 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -8,6 +8,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Drupal\Component\Utility\Crypt; use Drupal\Component\Uuid\Uuid; use Drupal\file\Plugin\Core\Entity\File; @@ -574,10 +575,7 @@ function image_style_deliver($style, $scheme) { if (!$lock_acquired) { // Tell client to retry again in 3 seconds. Currently no browsers are known // to support Retry-After. - drupal_add_http_header('Status', '503 Service Unavailable'); - drupal_add_http_header('Retry-After', 3); - print t('Image generation in progress. Try again shortly.'); - drupal_exit(); + throw new ServiceUnavailableHttpException(3, t('Image generation in progress. Try again shortly.')); } } diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 5173132..d8db907 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -5,6 +5,7 @@ * Mass import-export and batch import functionality for Gettext .po files. */ +use Symfony\Component\HttpFoundation\BinaryFileResponse; use Drupal\Component\Gettext\PoStreamWriter; use Drupal\locale\Gettext; use Drupal\locale\PoDatabaseReader; @@ -254,10 +255,11 @@ function locale_translate_export_form_submit($form, &$form_state) { $writer->writeItems($reader); $writer->close(); - header("Content-Disposition: attachment; filename=$filename"); - header("Content-Type: text/plain; charset=utf-8"); - print file_get_contents($uri); - drupal_exit(); + $response = new BinaryFileResponse($uri); + $response->setContentDisposition('attachment', $filename); + // @todo remove lines below once converted to new routing system. + $response->prepare(Drupal::request()) + ->send(); } else { drupal_set_message('Nothing to export.'); diff --git a/core/modules/openid/openid.inc b/core/modules/openid/openid.inc index 8d5aae9..2394023 100644 --- a/core/modules/openid/openid.inc +++ b/core/modules/openid/openid.inc @@ -5,6 +5,9 @@ * OpenID utility functions. */ +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\RedirectResponse; + /** * Diffie-Hellman Key Exchange Default Value. * @@ -74,9 +77,13 @@ function openid_redirect_http($url, $message) { } $sep = (strpos($url, '?') === FALSE) ? '?' : '&'; - header('Location: ' . $url . $sep . implode('&', $query), TRUE, 302); - drupal_exit(); + $response = new RedirectResponse($url . $sep . implode('&', $query)); + // @todo fix this. + $response->prepare(Drupal::request()); + $response->send(); + drupal_session_commit(); + exit; } /** @@ -97,9 +104,13 @@ function openid_redirect($url, $message) { $output .= '' . "\n"; $output .= "\n"; $output .= "\n"; - print $output; - drupal_exit(); + $response = new Response($output); + // @todo fix this. + $response->prepare(Drupal::request()); + $response->send(); + drupal_session_commit(); + exit; } function openid_redirect_form($form, &$form_state, $url, $message) { diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index 1cedd2e..c2f3245 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -588,8 +588,10 @@ function overlay_preprocess_page(&$variables) { */ function overlay_deliver_empty_page() { $empty_page = '' . drupal_get_css() . drupal_get_js() . ''; - print $empty_page; - drupal_exit(); + $response = new Response($empty_page); + // @todo remove lines below once converted to new routing system. + $response->send(); + exit; } /** diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 9d6d4b6..8260ca3 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -2130,8 +2130,9 @@ function system_run_cron() { * Menu callback: return information about PHP. */ function system_php() { + ob_start(); phpinfo(); - drupal_exit(); + return new Response(ob_get_clean()); } /** diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index c7a85a3..f171f48 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -5,6 +5,7 @@ * Helper module for the form API tests. */ +use Symfony\Component\HttpFoundation\JsonResponse; use Drupal\form_test\Callbacks; use Drupal\form_test\FormTestObject; use Drupal\form_test\SystemConfigFormTestForm; @@ -373,10 +374,9 @@ function form_test_permission() { * Form submit handler to return form values as JSON. */ function _form_test_submit_values_json($form, &$form_state) { - // This won't have a proper JSON header, but Drupal doesn't check for that - // anyway so this is fine until it's replaced with a JsonResponse. - print drupal_json_encode($form_state['values']); - drupal_exit(); + $response = new JsonResponse($form_state['values']); + // @todo remove once converted to new routing system. + $response->send(); } /** diff --git a/core/modules/xmlrpc/xmlrpc.server.inc b/core/modules/xmlrpc/xmlrpc.server.inc index e1c160b..50f41c7 100644 --- a/core/modules/xmlrpc/xmlrpc.server.inc +++ b/core/modules/xmlrpc/xmlrpc.server.inc @@ -5,6 +5,9 @@ * Page callback file for the xmlrpc module. */ +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; + /** * Process an XML-RPC request. */ @@ -71,8 +74,7 @@ function xmlrpc_server($callbacks) { $data = file_get_contents('php://input'); if (!$data) { - print 'XML-RPC server accepts POST requests only.'; - drupal_exit(); + throw new BadRequestHttpException('XML-RPC server accepts POST requests only.'); } $xmlrpc_server->message = xmlrpc_message($data); if (!xmlrpc_message_parse($xmlrpc_server->message)) { @@ -131,10 +133,13 @@ function xmlrpc_server_error($error, $message = FALSE) { */ function xmlrpc_server_output($xml) { $xml = '' . "\n" . $xml; - drupal_add_http_header('Content-Length', strlen($xml)); - drupal_add_http_header('Content-Type', 'text/xml'); - echo $xml; - drupal_exit(); + $headers = array( + 'Content-Length' => strlen($xml), + 'Content-Type' => 'text/xml' + ); + $response = new Response($xml, 200, $headers); + // @todo remove once converted to new routing system. + $response->send(); } /**