From 963d8b40c199fd49eb1de92f53ea214f9f2a66f8 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 10 Jun 2019 11:50:24 -0400 Subject: [PATCH] Have upload auto-ungzip If the server replies with gzip, automatically uncompress it. Change-Id: I3f0f5e9bdabf36b0fecd17b1ebd1a5b4d3734636 --- pyghmi/util/webclient.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index f62467da..ad2fc4da 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -258,7 +258,10 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): if rsp.status != 200: raise Exception('Unexpected response in file upload: ' + rsp.read()) - return rsp.read() + body = rsp.read() + if rsp.getheader('Content-Encoding', None) == 'gzip': + body = gzip.GzipFile(fileobj=StringIO.StringIO(body)).read() + return body def get_upload_progress(self): return float(self._upbuffer.tell()) / float(self.ulsize)