If this response has Content-Encoding set to something with "gzip", this function will decompress it and store it in the body.
(self)
| 178 | self.body = parse_body(self, data, self.headers) |
| 179 | |
| 180 | def decompress_gzip_content(self): |
| 181 | """ |
| 182 | If this response has Content-Encoding set to something with "gzip", |
| 183 | this function will decompress it and store it in the body. |
| 184 | """ |
| 185 | if "gzip" in self.headers.get("content-encoding", ""): |
| 186 | try: |
| 187 | iobody = io.BytesIO(self.body) |
| 188 | except TypeError as e: |
| 189 | # TODO: Why would body ever not be bytes? If it's not bytes, then that means |
| 190 | # we have a bug somewhere in the code and therefore should just allow the |
| 191 | # original exception to be raised. |
| 192 | self.errors.append(dshell.core.DataError("Body was not a byte string ({!s}). Could not decompress.".format(type(self.body)))) |
| 193 | return |
| 194 | try: |
| 195 | self.body = gzip.GzipFile(fileobj=iobody).read() |
| 196 | except OSError as e: |
| 197 | self.errors.append(OSError("Could not gunzip body. {!s}".format(e))) |
| 198 | return |
| 199 | |
| 200 | |
| 201 | class HTTPPlugin(dshell.core.ConnectionPlugin): |