Wrap bytes in a StringIO

Python httplib was making a copy of the data passed as bytes, completely
foiling the memory reduction attempt.  Change to StringIO to avoid
bulk copies and have python httplib itreate a bit at a time.

Change-Id: I923d8bac290f628ee10dd8a33e528a32f3d52a23
This commit is contained in:
Jarrod Johnson
2018-06-14 14:00:13 -04:00
parent 8b25601a7a
commit d4cfcd4919

View File

@@ -24,9 +24,11 @@ import ssl
try:
import Cookie
import httplib
import StringIO
except ImportError:
import http.client as httplib
import http.cookies as Cookie
import io as StringIO
__author__ = 'jjohnson2'
@@ -146,9 +148,11 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
"""
if data is None:
data = open(filename, 'rb')
form = get_upload_form(filename, data, formname, otherfields)
form = StringIO.StringIO(get_upload_form(filename, data, formname,
otherfields))
ulheaders = self.stdheaders.copy()
ulheaders['Content-Type'] = 'multipart/form-data; boundary=' + BND
ulheaders['Content-Length'] = len(uploadforms[filename])
webclient = self.dupe()
webclient.request('POST', url, form, ulheaders)
rsp = webclient.getresponse()