You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/09/12 19:20:33 UTC

[1/3] git commit: LIBCLOUD-396: Do not set Content-Length if present in raw requests

Updated Branches:
  refs/heads/trunk 95db9a169 -> 8764ffe3f


LIBCLOUD-396: Do not set Content-Length if present in raw requests

Signed-off-by: Tomaz Muraus <to...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/7179aace
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/7179aace
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/7179aace

Branch: refs/heads/trunk
Commit: 7179aacecebd3a0be303e59b49c5fc946200bb88
Parents: 95db9a1
Author: Ivan Kusalic <iv...@ikusalic.com>
Authored: Thu Sep 12 15:22:47 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Sep 12 17:43:27 2013 +0200

----------------------------------------------------------------------
 libcloud/common/base.py          |  9 +++------
 libcloud/test/test_connection.py | 16 +++++++++++++++-
 2 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/7179aace/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 101e66c..43cd82f 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -572,13 +572,10 @@ class Connection(object):
             headers.update({'Host': self.host})
 
         if data:
-            # Encode data if provided
             data = self.encode_data(data)
-            headers.update({'Content-Length': str(len(data))})
-        else:
-            # Only send Content-Length 0 with POST and PUT request
-            if method.upper() in ['POST', 'PUT']:
-                headers.update({'Content-Length': '0'})
+            headers['Content-Length'] = str(len(data))
+        elif method.upper() in ['POST', 'PUT'] and not raw:
+            headers['Content-Length'] = '0'
 
         params, headers = self.pre_connect_hook(params, headers)
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7179aace/libcloud/test/test_connection.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_connection.py b/libcloud/test/test_connection.py
index 798f7ec..646d253 100644
--- a/libcloud/test/test_connection.py
+++ b/libcloud/test/test_connection.py
@@ -17,7 +17,7 @@
 import sys
 import unittest
 
-from mock import Mock
+from mock import Mock, call
 
 from libcloud.common.base import Connection
 
@@ -68,6 +68,20 @@ class ConnectionClassTestCase(unittest.TestCase):
             call_kwargs = con.connection.request.call_args[1]
             self.assertEqual(call_kwargs['headers']['Content-Length'], '0')
 
+        # No data, raw request, do not touch Content-Length if present
+        for method in ['POST', 'PUT', 'post', 'put']:
+            con.request('/test', method=method, data=None,
+                        headers={'Content-Length': '42'}, raw=True)
+            putheader_call_list = con.connection.putheader.call_args_list
+            self.assertIn(call('Content-Length', '42'), putheader_call_list)
+
+        # '' as data, raw request, do not touch Content-Length if present
+        for method in ['POST', 'PUT', 'post', 'put']:
+            con.request('/test', method=method, data=None,
+                        headers={'Content-Length': '42'}, raw=True)
+            putheader_call_list = con.connection.putheader.call_args_list
+            self.assertIn(call('Content-Length', '42'), putheader_call_list)
+
         # 'a' as data, content length should be present
         for method in ['POST', 'PUT', 'post', 'put']:
             con.request('/test', method=method, data='a')


[3/3] git commit: Update changes.

Posted by to...@apache.org.
Update changes.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/8764ffe3
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/8764ffe3
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/8764ffe3

Branch: refs/heads/trunk
Commit: 8764ffe3f304b5b8b17d05bd009f2ae7fa819486
Parents: b3fb8f8
Author: Tomaz Muraus <to...@apache.org>
Authored: Thu Sep 12 17:43:10 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Sep 12 17:43:44 2013 +0200

----------------------------------------------------------------------
 CHANGES | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/8764ffe3/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 520a483..b0bd736 100644
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,12 @@ Changes with Apache Libcloud in development
       updating the pricing file.
       [Tomaz Muraus]
 
+    - Don't sent Content-Length: 0 header with POST and PUT request if "raw"
+      mode is used. This fixes a regression which could cause broken behavior
+      in some storage driver when uploading a file from disk.
+      (LIBCLOUD-396)
+      [Ivan Kusalic]
+
  *) Compute
 
     - Deprecate CLOUDFILES_US and CLOUDFILES_UK storage provider constants and


[2/3] git commit: Add a comment which clarifies why Content-Length: 0 is not sent if "raw" mode is used.

Posted by to...@apache.org.
Add a comment which clarifies why Content-Length: 0 is not sent if "raw" mode is
used.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/b3fb8f85
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/b3fb8f85
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/b3fb8f85

Branch: refs/heads/trunk
Commit: b3fb8f85186c8d3032a2ddaeaf32c820356a161f
Parents: 7179aac
Author: Tomaz Muraus <to...@apache.org>
Authored: Thu Sep 12 17:35:31 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Sep 12 17:43:44 2013 +0200

----------------------------------------------------------------------
 libcloud/common/base.py | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b3fb8f85/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 43cd82f..48e677b 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -575,6 +575,12 @@ class Connection(object):
             data = self.encode_data(data)
             headers['Content-Length'] = str(len(data))
         elif method.upper() in ['POST', 'PUT'] and not raw:
+            # Only send Content-Length 0 with POST and PUT request.
+            #
+            # Note: Content-Length is not added when using "raw" mode means
+            # means that headers are upfront and the body is sent at some point
+            # later on. With raw mode user can specify Content-Length with
+            # "data" not being set.
             headers['Content-Length'] = '0'
 
         params, headers = self.pre_connect_hook(params, headers)