Skip to content

Commit

Permalink
core: services: helper: main: Deal with gzip index files
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric committed Jun 25, 2024
1 parent deb3124 commit 3417d0e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/services/helper/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import asyncio
import gzip
import http.client
import json
import logging
Expand All @@ -9,6 +10,7 @@
from concurrent import futures
from datetime import datetime
from enum import Enum
from io import BytesIO
from typing import Any, Dict, List, Optional, Set, Union
from urllib.parse import urlparse

Expand Down Expand Up @@ -265,7 +267,14 @@ def simple_http_request(
request_response.status = response.status
if response.status == http.client.OK:
encoding = response.headers.get_content_charset() or "utf-8"
request_response.decoded_data = response.read().decode(encoding)
if response.getheader('Content-Encoding') == 'gzip':
buffer = BytesIO(response.read())
with gzip.GzipFile(fileobj=buffer) as file:
decompressed_data = file.read()
else:
decompressed_data = response.read()

request_response.decoded_data = decompressed_data.decode(encoding)

# Interpret it as json
if try_json:
Expand Down

0 comments on commit 3417d0e

Please sign in to comment.