Blame SOURCES/0053-v2v-o-rhv-upload-Optimize-http-request-sending.patch

e9bfca
From dc6afe583853bc2e18a689aa06685e69d65ede84 Mon Sep 17 00:00:00 2001
e9bfca
From: Nir Soffer <nirsof@gmail.com>
e9bfca
Date: Thu, 14 Jun 2018 21:16:01 +0300
e9bfca
Subject: [PATCH] v2v: -o rhv-upload: Optimize http request sending
e9bfca
e9bfca
When sending request with small or no payload, it is simpler and
e9bfca
possibly more efficient to use the high level HTTPSConnection.request(),
e9bfca
instead of the lower level APIs.
e9bfca
e9bfca
The only reason to use the lower level APIs is to avoid copying the
e9bfca
payload, or on python 2, to use a bigger buffer size when streaming a
e9bfca
file-like object.
e9bfca
e9bfca
(cherry picked from commit 77a412c0a1cd0e303a072fc5088c8f3bfed36583)
e9bfca
---
e9bfca
 v2v/rhv-upload-plugin.py | 35 ++++++++++++++++-------------------
e9bfca
 1 file changed, 16 insertions(+), 19 deletions(-)
e9bfca
e9bfca
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
e9bfca
index b4557b83c..9ad354b84 100644
e9bfca
--- a/v2v/rhv-upload-plugin.py
e9bfca
+++ b/v2v/rhv-upload-plugin.py
e9bfca
@@ -237,12 +237,12 @@ def pread(h, count, offset):
e9bfca
     transfer = h['transfer']
e9bfca
     transfer_service = h['transfer_service']
e9bfca
 
e9bfca
-    http.putrequest("GET", h['path'])
e9bfca
+    headers = {"Range", "bytes=%d-%d" % (offset, offset+count-1)}
e9bfca
     # Authorization is only needed for old imageio.
e9bfca
     if h['needs_auth']:
e9bfca
-        http.putheader("Authorization", transfer.signed_ticket)
e9bfca
-    http.putheader("Range", "bytes=%d-%d" % (offset, offset+count-1))
e9bfca
-    http.endheaders()
e9bfca
+        headers["Authorization"] = transfer.signed_ticket
e9bfca
+
e9bfca
+    http.request("GET", h['path'], headers=headers)
e9bfca
 
e9bfca
     r = http.getresponse()
e9bfca
     # 206 = HTTP Partial Content.
e9bfca
@@ -297,11 +297,10 @@ def zero(h, count, offset, may_trim):
e9bfca
                       'size': count,
e9bfca
                       'flush': False}).encode()
e9bfca
 
e9bfca
-    http.putrequest("PATCH", h['path'])
e9bfca
-    http.putheader("Content-Type", "application/json")
e9bfca
-    http.putheader("Content-Length", len(buf))
e9bfca
-    http.endheaders()
e9bfca
-    http.send(buf)
e9bfca
+    headers = {"Content-Type": "application/json",
e9bfca
+               "Content-Length": str(len(buf))}
e9bfca
+
e9bfca
+    http.request("PATCH", h['path'], body=buf, headers=headers)
e9bfca
 
e9bfca
     r = http.getresponse()
e9bfca
     if r.status != 200:
e9bfca
@@ -349,11 +348,10 @@ def trim(h, count, offset):
e9bfca
                       'size': count,
e9bfca
                       'flush': False}).encode()
e9bfca
 
e9bfca
-    http.putrequest("PATCH", h['path'])
e9bfca
-    http.putheader("Content-Type", "application/json")
e9bfca
-    http.putheader("Content-Length", len(buf))
e9bfca
-    http.endheaders()
e9bfca
-    http.send(buf)
e9bfca
+    headers = {"Content-Type": "application/json",
e9bfca
+               "Content-Length": str(len(buf))}
e9bfca
+
e9bfca
+    http.request("PATCH", h['path'], body=buf, headers=headers)
e9bfca
 
e9bfca
     r = http.getresponse()
e9bfca
     if r.status != 200:
e9bfca
@@ -370,11 +368,10 @@ def flush(h):
e9bfca
     # Construct the JSON request for flushing.
e9bfca
     buf = json.dumps({'op': "flush"}).encode()
e9bfca
 
e9bfca
-    http.putrequest("PATCH", h['path'])
e9bfca
-    http.putheader("Content-Type", "application/json")
e9bfca
-    http.putheader("Content-Length", len(buf))
e9bfca
-    http.endheaders()
e9bfca
-    http.send(buf)
e9bfca
+    headers = {"Content-Type": "application/json",
e9bfca
+               "Content-Length": str(len(buf))}
e9bfca
+
e9bfca
+    http.request("PATCH", h['path'], body=buf, headers=headers)
e9bfca
 
e9bfca
     r = http.getresponse()
e9bfca
     if r.status != 200:
e9bfca
-- 
e9bfca
2.17.1
e9bfca