Skip to content

Commit

Permalink
Fix Mime type guessing
Browse files Browse the repository at this point in the history
  • Loading branch information
danielskeenan authored and onigoetz committed Aug 8, 2019
1 parent 3c3ffa8 commit a17b3d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
21 changes: 19 additions & 2 deletions libs/Server/ExtensionMimeTypeGuesser.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php namespace Todaymade\Daux\Server;

use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface as FileMimeTypeGuesserInterface;
use Symfony\Component\Mime\MimeTypeGuesserInterface;

/**
* Guesses the mime type using the file's extension
*/
class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface
class ExtensionMimeTypeGuesser implements FileMimeTypeGuesserInterface, MimeTypeGuesserInterface
{
/**
* {@inheritdoc}
Expand All @@ -22,4 +23,20 @@ public function guess($path)
return "application/javascript";
}
}

/**
* {@inheritdoc}
*/
public function isGuesserSupported(): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function guessMimeType(string $path): ?string
{
return $this->guess($path);
}
}
5 changes: 3 additions & 2 deletions libs/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
use Symfony\Component\Mime\MimeTypes;
use Todaymade\Daux\Daux;
use Todaymade\Daux\DauxHelper;
use Todaymade\Daux\Exception;
Expand Down Expand Up @@ -97,7 +97,8 @@ private function getTemporaryFile($postfix) {
*/
public function createResponse(Page $page) {

MimeTypeGuesser::getInstance()->register(new ExtensionMimeTypeGuesser);
$mimeTypes = MimeTypes::getDefault();
$mimeTypes->registerGuesser(new ExtensionMimeTypeGuesser());

if ($page instanceof RawPage) {
return new BinaryFileResponse($page->getFile());
Expand Down

0 comments on commit a17b3d7

Please sign in to comment.