Skip to content

Commit

Permalink
[Headers] Automatically add content-type when there are datas
Browse files Browse the repository at this point in the history
  • Loading branch information
GeLoLabs committed Apr 19, 2015
1 parent 2b5a91a commit 19a0e44
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/AbstractHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected function prepareHeaders(
}

if (!$internalRequest->hasHeader('Content-Type')) {
$rawDatas = (string) $internalRequest->getBody();
$datas = $internalRequest->getDatas();
$files = $internalRequest->getFiles();

Expand All @@ -89,7 +90,7 @@ protected function prepareHeaders(
'Content-Type',
ConfigurationInterface::ENCODING_TYPE_FORMDATA.'; boundary='.$this->configuration->getBoundary()
);
} elseif ($contentType && !empty($datas)) {
} elseif ($contentType && (!empty($datas) || !empty($rawDatas))) {
$internalRequest = $internalRequest->withHeader(
'Content-Type',
ConfigurationInterface::ENCODING_TYPE_URLENCODED
Expand Down
4 changes: 0 additions & 4 deletions tests/AbstractHttpAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ public function testSendRequest($uri, $method, array $headers = array(), array $
http_build_query($data, null, '&')
);

if (!empty($data)) {
$this->httpAdapter->getConfiguration()->setEncodingType(ConfigurationInterface::ENCODING_TYPE_URLENCODED);
}

$options = array();
if ($method === Request::METHOD_HEAD) {
$options['body'] = null;
Expand Down

0 comments on commit 19a0e44

Please sign in to comment.