8000 [HttpFoundation] Request without content-type or content-length header should result in null values, not empty strings by priyadi · Pull Request #53432 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Request without content-type or content-length header should result in null values, not empty strings #53432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/ServerBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getHeaders()
foreach ($this->parameters as $key => $value) {
if (str_starts_with($key, 'HTTP_')) {
$headers[substr($key, 5)] = $value;
} elseif (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], true)) {
} elseif (\in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH', 'CONTENT_MD5'], true) && '' !== $value) {
$headers[$key] = $value;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/ServerBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,20 @@ public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet()
'PHP_AUTH_PW' => '',
], $bag->getHeaders());
}

/**
* An HTTP request without content-type and content-length will result in
* the variables $_SERVER['CONTENT_TYPE'] and $_SERVER['CONTENT_LENGTH']
* containing an empty string in PHP.
*/
public function testRequestWithoutContentTypeAndContentLength()
{
$bag = new ServerBag([
'CONTENT_TYPE' => '',
'CONTENT_LENGTH' => '',
'HTTP_USER_AGENT' => 'foo',
]);

$this->assertSame(['USER_AGENT' => 'foo'], $bag->getHeaders());
}
}
0