From ebfb1ab1e2b25ed1737fa9350eb673b716651cd3 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Wed, 18 Jan 2017 19:46:32 +0100
Subject: [PATCH] HTTPClient always set Content-Lenght with body. fixes #1782

http://stackoverflow.com/a/33005329/172068 tells us that we never need
to send it when it's zero. Which it always is for GET. That means we can
always send it for non-zero values.
---
 inc/HTTPClient.php | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php
index 49bb5d1a7..88a86c6bc 100644
--- a/inc/HTTPClient.php
+++ b/inc/HTTPClient.php
@@ -305,10 +305,15 @@ class HTTPClient {
                     $data = $this->_postEncode($data);
                 }
             }
-            $headers['Content-Length'] = strlen($data);
         }elseif($method == 'GET'){
             $data = ''; //no data allowed on GET requests
         }
+
+        $contentlength = strlen($data);
+        if($contentlength)  {
+            $headers['Content-Length'] = $contentlength;
+        }
+
         if($this->user) {
             $headers['Authorization'] = 'Basic '.base64_encode($this->user.':'.$this->pass);
         }
-- 
GitLab