From 3b7f074557bf240184c0d1fc962035df0ede600b Mon Sep 17 00:00:00 2001 From: Brooke Bryan Date: Fri, 15 Nov 2019 17:57:52 +0000 Subject: [PATCH] Set content length for empty requests --- src/Connections/RequestsConnection.php | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Connections/RequestsConnection.php b/src/Connections/RequestsConnection.php index 534b9df..803a4a2 100644 --- a/src/Connections/RequestsConnection.php +++ b/src/Connections/RequestsConnection.php @@ -9,8 +9,7 @@ use Fortifi\Api\Core\IApiRequest; use Fortifi\Api\Core\IApiResult; use Requests; -use Requests_Hooks; -use function in_array; +use function array_filter; class RequestsConnection extends AbstractConnection { @@ -34,22 +33,18 @@ public function load(IApiRequest $request) try { - $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; - } - } - ); + $headers = $this->_buildHeaders($req); + $data = $this->_buildData($req); + if(empty(array_filter($data))) + { + // Prevent 411 errors from some servers + $headers['Content-Length'] = 0; + } $response = Requests::request( $req->getUrl(), - $this->_buildHeaders($req), - $this->_buildData($req), + $headers, + $data, $req->getMethod(), array_merge(['timeout' => $this->_timeout], (array)$req->getOptions()) );