- πΊπ¦Ukraine mykola dolynskyi Poltava
had such issue, first request respects _format=json and next for the same server invocations are not.
after wasted hours of tracing and debugging I ended up with adding custom middleware
<?php namespace Drupal\xxx; use Drupal\Core\Http\InputBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpFoundation\InputBag as SymfonyInputBag; /** * FirstMiddleware middleware. */ class RequestFormatMiddleware implements HttpKernelInterface { /** * The kernel. * * @var \Symfony\Component\HttpKernel\HttpKernelInterface */ protected $httpKernel; /** * Constructs the FirstMiddleware object. * * @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel * The decorated kernel. */ public function __construct(HttpKernelInterface $http_kernel) { $this->httpKernel = $http_kernel; } /** * {@inheritdoc} */ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) { if(empty($request->getRequestFormat(null)) && !empty($request->get('_format'))) { $request->setRequestFormat($request->get('_format')); } Request::setFactory( function ($query, $request, $attributes, $cookies, $files, $server, $content) { $current = \Drupal::request(); if(empty($attributes['_format']) && !empty($current->getRequestFormat(null))) { $attributes['_format'] = $current->getRequestFormat(null); } $request = new Request($query, $request, $attributes, $cookies, $files, $server, $content); foreach (['request', 'query', 'cookies'] as $bag) { if (!($bag instanceof SymfonyInputBag)) { $request->$bag = new InputBag($request->$bag->all()); } } return $request; } ); return $this->httpKernel->handle($request, $type, $catch); } }