diff --git a/core/core.services.yml b/core/core.services.yml index 1aadb75f0c0..98c87cad8a1 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -630,12 +630,8 @@ services: http_kernel.basic: class: Symfony\Component\HttpKernel\HttpKernel arguments: ['@event_dispatcher', '@controller_resolver', '@request_stack'] - http_negotiation.format_negotiator: - class: Drupal\Core\ContentNegotiation - private: true http_middleware.negotiation: class: Drupal\Core\StackMiddleware\NegotiationMiddleware - arguments: ['@http_negotiation.format_negotiator'] tags: - { name: http_middleware, priority: 400 } http_middleware.reverse_proxy: diff --git a/core/lib/Drupal/Core/ContentNegotiation.php b/core/lib/Drupal/Core/ContentNegotiation.php deleted file mode 100644 index 10237ab8fda..00000000000 --- a/core/lib/Drupal/Core/ContentNegotiation.php +++ /dev/null @@ -1,43 +0,0 @@ -. - if ($request->get('ajax_iframe_upload', FALSE)) { - return 'iframeupload'; - } - - if ($request->query->has('_format')) { - return $request->query->get('_format'); - } - - // Do HTML last so that it always wins. - return 'html'; - } -} diff --git a/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php b/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php index 57d905432d5..65f426aeb62 100644 --- a/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php +++ b/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php @@ -7,8 +7,6 @@ namespace Drupal\Core\StackMiddleware; -use Drupal\Core\ContentNegotiation; -use Drupal\Core\ContentNegotiationInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -26,13 +24,6 @@ class NegotiationMiddleware implements HttpKernelInterface { */ protected $app; - /** - * The content negotiator. - * - * @var \Drupal\Core\ContentNegotiation - */ - protected $negotiator; - /** * Contains a hashmap of format as key and mimetype as value. * @@ -45,12 +36,9 @@ class NegotiationMiddleware implements HttpKernelInterface { * * @param \Symfony\Component\HttpKernel\HttpKernelInterface $app * The wrapper HTTP kernel - * @param \Drupal\Core\ContentNegotiation $negotiator - * The content negotiator. */ - public function __construct(HttpKernelInterface $app, ContentNegotiation $negotiator) { + public function __construct(HttpKernelInterface $app) { $this->app = $app; - $this->negotiator = $negotiator; } /** @@ -63,7 +51,7 @@ class NegotiationMiddleware implements HttpKernelInterface { } // Determine the request format using the negotiator. - $request->setRequestFormat($this->negotiator->getContentType($request)); + $request->setRequestFormat($this->getContentType($request)); return $this->app->handle($request, $type, $catch); } @@ -82,4 +70,31 @@ class NegotiationMiddleware implements HttpKernelInterface { return $this; } + /** + * Gets the normalized type of a request. + * + * The normalized type is a short, lowercase version of the format, such as + * 'html', 'json' or 'atom'. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * The request object from which to extract the content type. + * + * @return string + * The normalized type of a given request. + */ + protected function getContentType(Request $request) { + // AJAX iframe uploads need special handling, because they contain a JSON + // response wrapped in