Skip to content

Commit

Permalink
Removed request header "Content-Type" from the preferred format guess…
Browse files Browse the repository at this point in the history
…ing mechanism
  • Loading branch information
yceruto committed Dec 10, 2019
1 parent 3439147 commit da246f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 5 additions & 8 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1586,20 +1586,17 @@ public function isNoCache()
*/
public function getPreferredFormat(?string $default = 'html'): ?string
{
if (null !== $this->preferredFormat) {
if (null !== $this->preferredFormat || null !== $this->preferredFormat = $this->getRequestFormat(null)) {
return $this->preferredFormat;
}

$preferredFormat = null;
foreach ($this->getAcceptableContentTypes() as $contentType) {
if ($preferredFormat = $this->getFormat($contentType)) {
break;
foreach ($this->getAcceptableContentTypes() as $mimeType) {
if ($this->preferredFormat = $this->getFormat($mimeType)) {
return $this->preferredFormat;
}
}

$this->preferredFormat = $this->getRequestFormat($preferredFormat ?: $this->getContentType());

return $this->preferredFormat ?: $default;
return $default;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,10 @@ public function testGetPreferredFormat()

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

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

$request = new Request();
Expand Down

0 comments on commit da246f4

Please sign in to comment.