1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 08:40:34 +03:00

add deflate support

This commit is contained in:
A_D 2022-01-25 15:09:30 +02:00
parent 45dba2ba88
commit 10824250e1
No known key found for this signature in database
GPG Key ID: 4BE9EB7DF45076C4

View File

@ -4,6 +4,7 @@ import json
import pathlib import pathlib
import tempfile import tempfile
import threading import threading
import zlib
from http import server from http import server
from typing import Any, Callable, Tuple, Union from typing import Any, Callable, Tuple, Union
from urllib.parse import parse_qs from urllib.parse import parse_qs
@ -34,6 +35,16 @@ class LoggingHandler(server.BaseHTTPRequestHandler):
data_raw: bytes = self.rfile.read(int(self.headers['Content-Length'])) data_raw: bytes = self.rfile.read(int(self.headers['Content-Length']))
data: str | bytes data: str | bytes
match self.headers.get('Content-Encoding'):
case 'gzip':
data = gzip.decompress(data_raw).decode('utf-8', errors='replace')
case 'deflate':
zlib.decompress(data_raw).decode('utf-8', errors='replace')
case _:
data = data_raw.decode('utf-8', errors='replace')
if self.headers.get('Content-Encoding') == 'gzip': if self.headers.get('Content-Encoding') == 'gzip':
data = gzip.decompress(data_raw).decode('utf-8', errors='replace') data = gzip.decompress(data_raw).decode('utf-8', errors='replace')