diff --git a/README.md b/README.md index d7b5827..dd4d82a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Python-TLS-Client -Python-TLS-Client is an advanced HTTP library based on requests and tls-client. +Python-TLS-Client is an advanced HTTP library based on requests and tls-client. To use this fork to download images, etc. add byte_response=True kwarg when making a request. Write response.byte_content to files. # Installation ``` diff --git a/tls_client/response.py b/tls_client/response.py index 8447ae5..0d93dca 100644 --- a/tls_client/response.py +++ b/tls_client/response.py @@ -2,6 +2,7 @@ from .structures import CaseInsensitiveDict from typing import Union +import base64 import json @@ -75,4 +76,9 @@ def build_response(res: Union[dict, list], res_cookies: RequestsCookieJar) -> Re response.text = res["body"] # Add response content (bytes) response._content = res["body"].encode() + # Add content for isByteResponse + try: + response.byte_content = base64.urlsafe_b64decode(res["body"].split(",")[1]) + except ValueError: + response.byte_content = b'' return response diff --git a/tls_client/sessions.py b/tls_client/sessions.py index e625669..42ffd62 100644 --- a/tls_client/sessions.py +++ b/tls_client/sessions.py @@ -314,6 +314,7 @@ def execute_request( insecure_skip_verify: Optional[bool] = False, timeout_seconds: Optional[int] = None, proxy: Optional[dict] = None # Optional[dict[str, str]] + byte_response: bool = False # Set to True if request is for content ) -> Response: # --- URL ------------------------------------------------------------------------------------------------------ # Prepare URL - add params to url @@ -397,6 +398,7 @@ def execute_request( "headerOrder": self.header_order, "insecureSkipVerify": insecure_skip_verify, "isByteRequest": is_byte_request, + "isByteResponse": byte_response, # adding byte response "additionalDecode": self.additional_decode, "proxyUrl": proxy, "requestUrl": url,