mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-24 18:13:00 +01:00
Using the Content-Type of the EntityBody if one cannot be determined by the request path
This commit is contained in:
parent
863998bbdb
commit
6f044c5c7e
@ -142,9 +142,9 @@ class EntityBody extends Stream implements EntityBodyInterface
|
||||
*/
|
||||
public function getContentType()
|
||||
{
|
||||
return (!($this->isLocal() && $this->getWrapper() == 'plainfile' && file_exists($this->getUri())))
|
||||
? null
|
||||
: Mimetypes::getInstance()->fromFilename($this->getUri());
|
||||
return ($this->isLocal() && $this->getWrapper() == 'plainfile' && file_exists($this->getUri()))
|
||||
? Mimetypes::getInstance()->fromFilename($this->getUri())
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,7 +81,7 @@ class EntityEnclosingRequest extends Request implements EntityEnclosingRequestIn
|
||||
|
||||
// Auto detect the Content-Type from the path of the request if possible
|
||||
if ($contentType === null && !$this->hasHeader('Content-Type')) {
|
||||
$contentType = Mimetypes::getInstance()->fromFilename($this->getPath());
|
||||
$contentType = Mimetypes::getInstance()->fromFilename($this->getPath()) ?: $this->body->getContentType();
|
||||
}
|
||||
|
||||
if ($contentType) {
|
||||
|
@ -525,10 +525,20 @@ class EntityEnclosingRequestTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
/**
|
||||
* @covers Guzzle\Http\Message\EntityEnclosingRequest::setBody
|
||||
*/
|
||||
public function testSetsContentTypeWhenSettingBodyByGuessing()
|
||||
public function testSetsContentTypeWhenSettingBodyByGuessingFromPath()
|
||||
{
|
||||
$request = new EntityEnclosingRequest('PUT', 'http://test.com/foo.json');
|
||||
$request->setBody('{"a":"b"}');
|
||||
$this->assertEquals('application/json', $request->getHeader('Content-Type'));
|
||||
$this->assertEquals('application/json', (string) $request->getHeader('Content-Type'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Guzzle\Http\Message\EntityEnclosingRequest::setBody
|
||||
*/
|
||||
public function testSetsContentTypeWhenSettingBodyByGuessingFromEntityBody()
|
||||
{
|
||||
$request = new EntityEnclosingRequest('PUT', 'http://test.com/foo');
|
||||
$request->setBody(EntityBody::factory(fopen(__FILE__, 'r')));
|
||||
$this->assertEquals('text/x-php', (string) $request->getHeader('Content-Type'));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user