mirror of https://github.com/MISP/PyMISP
new: Support brotli compression
parent
de6125a623
commit
361d8d0944
|
@ -15,6 +15,7 @@ from uuid import UUID
|
||||||
import warnings
|
import warnings
|
||||||
import sys
|
import sys
|
||||||
import copy
|
import copy
|
||||||
|
import urllib3
|
||||||
from io import BytesIO, StringIO
|
from io import BytesIO, StringIO
|
||||||
|
|
||||||
from . import __version__, everything_broken
|
from . import __version__, everything_broken
|
||||||
|
@ -87,6 +88,27 @@ def register_user(misp_url: str, email: str,
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
def brotli_supported() -> bool:
|
||||||
|
"""
|
||||||
|
Returns whether Brotli compression is supported
|
||||||
|
"""
|
||||||
|
|
||||||
|
# urllib >= 1.25.1 includes brotli support
|
||||||
|
major, minor, patch = urllib3.__version__.split('.') # noqa: F811
|
||||||
|
major, minor, patch = int(major), int(minor), int(patch)
|
||||||
|
urllib3_with_brotli = (major == 1 and ((minor == 25 and patch >= 1) or (minor >= 26))) or major >= 2
|
||||||
|
|
||||||
|
if not urllib3_with_brotli:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# pybrotli is an extra package required by urllib3 for brotli support
|
||||||
|
try:
|
||||||
|
import brotli
|
||||||
|
return True
|
||||||
|
except ImportError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class PyMISP:
|
class PyMISP:
|
||||||
"""Python API for MISP
|
"""Python API for MISP
|
||||||
|
|
||||||
|
@ -117,6 +139,8 @@ class PyMISP:
|
||||||
self.tool: str = tool
|
self.tool: str = tool
|
||||||
self.timeout: Optional[Union[float, Tuple[float, float]]] = timeout
|
self.timeout: Optional[Union[float, Tuple[float, float]]] = timeout
|
||||||
self.__session = requests.Session() # use one session to keep connection between requests
|
self.__session = requests.Session() # use one session to keep connection between requests
|
||||||
|
if brotli_supported():
|
||||||
|
self.__session.headers['Accept-Encoding'] = ', '.join(('br', 'gzip', 'deflate'))
|
||||||
|
|
||||||
self.global_pythonify = False
|
self.global_pythonify = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue