Skip to content

[HttpFoundation] static Request::$formats can't be reset which causes issues in worker mode #59036

@soyuka

Description

@soyuka

Symfony version(s) affected

6.4, 7.1

Description

In API Platform, we need to add formats per-request. Indeed, each HTTP operation can be configured with specific mime-types.

To do so, we use Request::setFormat:

public function setFormat(?string $format, string|array $mimeTypes): void
{
if (null === static::$formats) {
static::initializeFormats();
}
static::$formats[$format] = \is_array($mimeTypes) ? $mimeTypes : [$mimeTypes];

We recently stumbled on an issue in worker mode. Indeed as $formats is static, its values are sometimes the same as a previous request and we need to merge new formats (api-platform/core#6833) to bypass this issue.

Possible Solution

With @dunglas we were thinking of a few solutions:

  • either allow a way to restore Request::$formats in a ResetInterface to null (although this solution makes the static not so useful)
  • set a local variable (Request::$currentFormat) that would fallback on the static value if not defined. This would allow to set formats per-request.

Note: to reproduce we can use api-platform/core#6831 or the test at api-platform/core#6833

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy