Skip to content

Commit

Permalink
Put, Patch and Delete should set a content length
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Nov 15, 2019
1 parent 1b49238 commit 13fc6d9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Connections/RequestsConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Fortifi\Api\Core\Exceptions\Server\ServiceUnavailableException;
use Fortifi\Api\Core\IApiRequest;
use Fortifi\Api\Core\IApiResult;
use Requests;
use Requests_Hooks;
use function in_array;

class RequestsConnection extends AbstractConnection
{
Expand All @@ -31,7 +34,19 @@ public function load(IApiRequest $request)

try
{
$response = \Requests::request(
$hooker = new Requests_Hooks();
$hooker->register(
'requests.before_request',
function ($url, &$headers, $data, $method) {
if(in_array($method, [Requests::PATCH, Requests::PUT, Requests::DELETE]) && empty($data))
{
// Prevent 411 errors from some servers
$headers['Content-Length'] = 0;
}
}
);

$response = Requests::request(
$req->getUrl(),
$this->_buildHeaders($req),
$this->_buildData($req),
Expand Down

0 comments on commit 13fc6d9

Please sign in to comment.