Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
[HttpFoundation] Request without content-type or content-length heade…
…r should result in null values, not empty strings
  • Loading branch information
priyadi authored and nicolas-grekas committed Jan 23, 2024
commit 3a5b25cd6fee4f5d5f345332a3450dadad9dba26
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());
}
}