Skip to content

Commit

Permalink
minor #54590 [HttpFoundation] Remove unused code (minor) (smnandre)
Browse files Browse the repository at this point in the history
This PR was merged into the 7.1 branch.

Discussion
----------

[HttpFoundation] Remove unused code (minor)

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #...
| License       | MIT

Remove two unused var declarations (both are declared/computed just after)  (in green in the following code block)

```diff
        // headers
        foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
-            $newValues = $values;
-            $replace = false;

            // As recommended by RFC 8297, PHP automatically copies headers from previous 103 responses, we need to deal with that if headers changed
            $previousValues = $this->sentHeaders[$name] ?? null;
            if ($previousValues === $values) {
                // Header already sent in a previous response, it will be automatically copied in this response by PHP
                continue;
            }

+            $replace = 0 === strcasecmp($name, 'Content-Type');

            if (null !== $previousValues && array_diff($previousValues, $values)) {
                header_remove($name);
                $previousValues = null;
            }

+            $newValues = null === $previousValues ? $values : array_diff($values, $previousValues);

            foreach ($newValues as $value) {
                header($name.': '.$value, $replace, $this->statusCode);
            }
```

Commits
-------

08841af [HttpFoundation] Remove unused code (minor)
  • Loading branch information
nicolas-grekas committed Apr 16, 2024
2 parents 5028ec6 + 08841af commit 39a5fdc
Showing 1 changed file with 0 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/Symfony/Component/HttpFoundation/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ public function sendHeaders(?int $statusCode = null): static

// headers
foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
$newValues = $values;
$replace = false;

// As recommended by RFC 8297, PHP automatically copies headers from previous 103 responses, we need to deal with that if headers changed
$previousValues = $this->sentHeaders[$name] ?? null;
if ($previousValues === $values) {
Expand Down

0 comments on commit 39a5fdc

Please sign in to comment.