fix request get content type

This commit is contained in:
Yuri Kuznetsov
2021-05-06 09:26:16 +03:00
parent 9ce7239308
commit e9f7046a05
2 changed files with 38 additions and 1 deletions
+4 -1
View File
@@ -146,7 +146,10 @@ class RequestWrapper implements ApiRequest
return null;
}
$contentType = $this->request->getHeader('Content-Type')[0];
$contentType = explode(
';',
$this->request->getHeader('Content-Type')[0]
)[0];
return strtolower($contentType);
}
+34
View File
@@ -34,6 +34,8 @@ use Psr\Http\Message\{
StreamInterface,
};
use Slim\Psr7\Factory\RequestFactory;
use Espo\Core\Api\RequestWrapper;
class RequestTest extends \PHPUnit\Framework\TestCase
@@ -182,4 +184,36 @@ class RequestTest extends \PHPUnit\Framework\TestCase
$this->assertNotSame($parsed->key2->key21[2], $anotherParsed->key2->key21[2]);
}
public function testContentType1(): void
{
$request = (new RequestFactory())
->createRequest('POST', 'http://localhost/?')
->withHeader('Content-Type', 'application/json; charset=utf-8');
$requestWrapped = new RequestWrapper($request);
$this->assertEquals('application/json', $requestWrapped->getContentType());
}
public function testContentType2(): void
{
$request = (new RequestFactory())
->createRequest('POST', 'http://localhost/?')
->withHeader('Content-Type', 'application/json');
$requestWrapped = new RequestWrapper($request);
$this->assertEquals('application/json', $requestWrapped->getContentType());
}
public function testContentTypeEmpty(): void
{
$request = (new RequestFactory())
->createRequest('POST', 'http://localhost/?');
$requestWrapped = new RequestWrapper($request);
$this->assertEquals(null, $requestWrapped->getContentType());
}
}