Permalink
Browse files

Adding better mimetype guessing based on file extensions

  • Loading branch information...
1 parent 3ee2d5b commit eab17828625aa97b5e2e837176612c1d799291c0 @mtdowling mtdowling committed Nov 18, 2012
Showing with 969 additions and 13 deletions.
  1. +3 −4 EntityBody.php
  2. +2 −9 Message/PostFile.php
  3. +964 −0 Mimetypes.php
View
@@ -4,6 +4,7 @@
use Guzzle\Stream\Stream;
use Guzzle\Common\Exception\InvalidArgumentException;
+use Guzzle\Http\Mimetypes;
/**
* Entity body used with an HTTP request or response
@@ -139,13 +140,11 @@ public function getContentLength()
*/
public function getContentType()
{
- if (!class_exists('finfo', false) || !($this->isLocal() && $this->getWrapper() == 'plainfile' && file_exists($this->getUri()))) {
+ if (!($this->isLocal() && $this->getWrapper() == 'plainfile' && file_exists($this->getUri()))) {
return 'application/octet-stream';
}
- $finfo = new \finfo(FILEINFO_MIME_TYPE);
-
- return $finfo->file($this->getUri());
+ return Mimetypes::getInstance()->fromFilename($this->getUri()) ?: 'application/octet-stream';
}
/**
View
@@ -3,6 +3,7 @@
namespace Guzzle\Http\Message;
use Guzzle\Common\Exception\InvalidArgumentException;
+use Guzzle\Http\Mimetypes;
/**
* POST file upload
@@ -105,14 +106,6 @@ public function getCurlString()
*/
protected function guessContentType()
{
- // @codeCoverageIgnoreStart
- if (!class_exists('finfo', false)) {
- return 'application/octet-stream';
- }
- // @codeCoverageIgnoreEnd
-
- $finfo = new \finfo(FILEINFO_MIME_TYPE);
-
- return $finfo->file($this->filename);
+ return Mimetypes::getInstance()->fromFilename($this->filename) ?: 'application/octet-stream';
}
}
Oops, something went wrong.

0 comments on commit eab1782

Please sign in to comment.