Skip to content

TypeError when Cache-Control header is missing #42290

Closed
@metaer

Description

@metaer

Symfony version(s) affected: 5.3.5

Description
Uncaught PHP Exception TypeError: "Argument 1 passed to str_contains() must be of the type string, null given, called in vendor/symfony/http-foundation/Response.php on line 327" at vendor/symfony/polyfill-php80/bootstrap.php line 29

from Response.php:327:

if ('1.0' == $this->getProtocolVersion() && str_contains($headers->get('Cache-Control'), 'no-cache')) {

It seems that happens when $headers->get('Cache-Control') is null.

How to reproduce
Request with missing 'Cache-Control' header

Possible Solution
Pass default value '' in the second argument of get()
$headers->get('Cache-Control', '')

Additional info
phpDoc claims that method \Symfony\Component\HttpFoundation\HeaderBag::get can return string|null,
but str_contains can receive only string in the first argument

I can create PR with this solution

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