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

Skip to content

Commit 776523e

Browse files
committed
Removed request header "Content-Type" from the preferred format guessing mechanism
1 parent 4c50968 commit 776523e

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,20 +1586,17 @@ public function isNoCache()
15861586
*/
15871587
public function getPreferredFormat(?string $default = 'html'): ?string
15881588
{
1589-
if (null !== $this->preferredFormat) {
1589+
if (null !== $this->preferredFormat || null !== $this->preferredFormat = $this->getRequestFormat(null)) {
15901590
return $this->preferredFormat;
15911591
}
15921592

1593-
$preferredFormat = null;
1594-
foreach ($this->getAcceptableContentTypes() as $contentType) {
1595-
if ($preferredFormat = $this->getFormat($contentType)) {
1596-
break;
1593+
foreach ($this->getAcceptableContentTypes() as $mimeType) {
1594+
if ($this->preferredFormat = $this->getFormat($mimeType)) {
1595+
return $this->preferredFormat;
15971596
}
15981597
}
15991598

1600-
$this->preferredFormat = $this->getRequestFormat($preferredFormat ?: $this->getContentType());
1601-
1602-
return $this->preferredFormat ?: $default;
1599+
return $default;
16031600
}
16041601

16051602
/**

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,10 @@ public function testGetPreferredFormat()
408408

409409
$request->setRequestFormat('atom');
410410
$request->headers->set('Accept', 'application/ld+json');
411-
$request->headers->set('Content-Type', 'application/merge-patch+json');
412411
$this->assertSame('atom', $request->getPreferredFormat());
413412

414413
$request = new Request();
415414
$request->headers->set('Accept', 'application/xml');
416-
$request->headers->set('Content-Type', 'application/json');
417415
$this->assertSame('xml', $request->getPreferredFormat());
418416

419417
$request = new Request();

0 commit comments

Comments
 (0)