Repository: libcloud
Updated Branches:
  refs/heads/trunk 08f6c2c45 -> c452e7dbc


Use --head flag instead of -X HEAD when logging curl lines for HEAD requests in
debug mode.

Reported by Brian Metzler, part of LIBCLOUD-552.


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

Branch: refs/heads/trunk
Commit: c452e7dbc17efefdbfadd57820dc3f2ae0d126b4
Parents: 08f6c2c
Author: Tomaz Muraus <[email protected]>
Authored: Wed May 14 08:55:12 2014 +0200
Committer: Tomaz Muraus <[email protected]>
Committed: Wed May 14 08:59:53 2014 +0200

----------------------------------------------------------------------
 CHANGES.rst                      |  7 +++++++
 libcloud/common/base.py          |  6 +++++-
 libcloud/test/test_connection.py | 21 +++++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c452e7db/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 0e4ba16..6eb473c 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -12,6 +12,13 @@ General
   all the available images in the EC2 driver).
   [Andrew Mann]
 
+- Use --head flag instead of -X HEAD when logging curl lines for HEAD requests
+  in debug mode.
+
+  Reported by Brian Metzler.
+  (LIBCLOUD-552)
+  [Tomaz Muraus]
+
 Compute
 ~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c452e7db/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 5848c59..a42f228 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -331,7 +331,11 @@ class LoggingConnection():
     def _log_curl(self, method, url, body, headers):
         cmd = ["curl", "-i"]
 
-        cmd.extend(["-X", pquote(method)])
+        if method.lower() == 'head':
+            # HEAD method need special handling
+            cmd.extend(["--head"])
+        else:
+            cmd.extend(["-X", pquote(method)])
 
         for h in headers:
             cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c452e7db/libcloud/test/test_connection.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_connection.py b/libcloud/test/test_connection.py
index ed8999d..5df7919 100644
--- a/libcloud/test/test_connection.py
+++ b/libcloud/test/test_connection.py
@@ -21,6 +21,7 @@ from mock import Mock, call
 
 from libcloud.test import unittest
 from libcloud.common.base import Connection
+from libcloud.common.base import LoggingConnection
 
 
 class ConnectionClassTestCase(unittest.TestCase):
@@ -182,5 +183,25 @@ class ConnectionClassTestCase(unittest.TestCase):
 
         self.assertEqual(con.context, {})
 
+    def test_log_curl(self):
+        url = '/test/path'
+        body = None
+        headers = {}
+
+        con = LoggingConnection()
+        con.protocol = 'http'
+        con.host = 'example.com'
+        con.port = 80
+
+        for method in ['GET', 'POST', 'PUT', 'DELETE']:
+            cmd = con._log_curl(method=method, url=url, body=body,
+                                headers=headers)
+            self.assertEqual(cmd, 'curl -i -X %s --compress 
http://example.com:80/test/path' %
+                             (method))
+
+        # Should use --head for head requests
+        cmd = con._log_curl(method='HEAD', url=url, body=body, headers=headers)
+        self.assertEqual(cmd, 'curl -i --head --compress 
http://example.com:80/test/path')
+
 if __name__ == '__main__':
     sys.exit(unittest.main())

Reply via email to