The Wayback Machine - https://web.archive.org/web/20250528002237/https://github.com/symfony/symfony/issues/42290
Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TypeError when Cache-Control header is missing #42290

Copy link
Copy link
Closed
@metaer

Description

@metaer
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.