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

[HttpFoundation] 301 RedirectResponse ignores passed in cache-control header. #31862

Copy link
Copy link
Closed
@mrbaileys

Description

@mrbaileys
Issue body actions

Symfony version(s) affected: >= 3.2
Description

The constructor for \Symfony\Component\HttpFoundation\RedirectResponse removes the cache-control header for 301 responses, unless the caller explicitly provides a cache-control header through the $headers parameter (introduced in #17139.) However, the check on $headers['cache-control']in the constructor is case sensitive, so if the caller passes in $headers['Cache-Control'], the cache-control header is still being removed.

This was discovered in the Drupal issue queue (#3054821-10: Include Cache-Control header on 301 redirects.).

How to reproduce

$response = new RedirectResponse('foo.bar', 301, ['cache-control' => 'max-age=86400']);
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));

$response = new RedirectResponse('foo.bar', 301, ['Cache-Control' => 'max-age=86400']);
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));

The first unit test succeeds, the second one fails.

Possible Solution

Perform a case insensitive check on the user-supplied headers.

Additional context

This issue was raised earlier in #27574, but that issue was closed, although a comment by @curry684 said:

It's dodgy code for sure that could use some comments and improvements...

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.