summaryrefslogtreecommitdiffstats
path: root/g4f/cookies.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-22 17:55:31 +0200
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-22 17:55:31 +0200
commit6a05a238d9a480e05f636b2987e6e50ac8b60169 (patch)
tree499b140016740e9549daa93e4011f08c9443dab9 /g4f/cookies.py
parentUpdate cookies.py (diff)
downloadgpt4free-6a05a238d9a480e05f636b2987e6e50ac8b60169.tar
gpt4free-6a05a238d9a480e05f636b2987e6e50ac8b60169.tar.gz
gpt4free-6a05a238d9a480e05f636b2987e6e50ac8b60169.tar.bz2
gpt4free-6a05a238d9a480e05f636b2987e6e50ac8b60169.tar.lz
gpt4free-6a05a238d9a480e05f636b2987e6e50ac8b60169.tar.xz
gpt4free-6a05a238d9a480e05f636b2987e6e50ac8b60169.tar.zst
gpt4free-6a05a238d9a480e05f636b2987e6e50ac8b60169.zip
Diffstat (limited to 'g4f/cookies.py')
-rw-r--r--g4f/cookies.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/g4f/cookies.py b/g4f/cookies.py
index 4f0899b4..e1d7b59c 100644
--- a/g4f/cookies.py
+++ b/g4f/cookies.py
@@ -26,6 +26,12 @@ from . import debug
# Global variable to store cookies
_cookies: Dict[str, Cookies] = {}
+DOMAINS = [
+ ".bing.com",
+ ".meta.ai",
+ ".google.com"
+]
+
if has_browser_cookie3 and os.environ.get('DBUS_SESSION_BUS_ADDRESS') == "/dev/null":
_LinuxPasswordManager.get_password = lambda a, b: b"secret"
@@ -88,6 +94,15 @@ def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool
return cookies
def read_cookie_files(dirPath: str = "./har_and_cookies"):
+ def get_domain(v: dict) -> str:
+ host = [h["value"] for h in v['request']['headers'] if h["name"].lower() in ("host", ":authority")]
+ if not host:
+ return
+ host = host.pop()
+ for d in DOMAINS:
+ if d in host:
+ return d
+
global _cookies
harFiles = []
cookieFiles = []
@@ -109,17 +124,15 @@ def read_cookie_files(dirPath: str = "./har_and_cookies"):
print("Read .har file:", path)
new_cookies = {}
for v in harFile['log']['entries']:
+ domain = get_domain(v)
+ if domain is None:
+ continue
v_cookies = {}
for c in v['request']['cookies']:
- if "domain" not in c:
- continue
-
- if c['domain'] not in v_cookies:
- v_cookies[c['domain']] = {}
- v_cookies[c['domain']][c['name']] = c['value']
- for domain, c in v_cookies.items():
- _cookies[domain] = c
- new_cookies[domain] = len(c)
+ v_cookies[c['name']] = c['value']
+ if len(v_cookies) > 0:
+ _cookies[domain] = v_cookies
+ new_cookies[domain] = len(v_cookies)
if debug.logging:
for domain, new_values in new_cookies.items():
print(f"Cookies added: {new_values} from {domain}")