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 <[email protected]>
  • Loading branch information
patrickelectric committed Jun 25, 2024
1 parent deb3124 commit 4cc517f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions 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 @@ -211,7 +213,7 @@ class Helper:
PERIODICALLY_RESCAN_3RDPARTY_SERVICES = True

@staticmethod
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-branches,too-many-locals
def simple_http_request(
host: str,
port: int = http.client.HTTP_PORT,
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 4cc517f

Please sign in to comment.