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