From 83fea2bb7affe3ac041e8c65cad89565061b27b8 Mon Sep 17 00:00:00 2001 From: Kevin Reynolds Date: Thu, 2 May 2024 00:09:33 -0400 Subject: [PATCH] interesting --- labapp/app/app.py | 2 +- labapp/app/fetch.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/labapp/app/app.py b/labapp/app/app.py index 3de1359..11babf4 100644 --- a/labapp/app/app.py +++ b/labapp/app/app.py @@ -323,7 +323,7 @@ def manip2(): raise LabException("Ephemeral NS not set") base_url = app.config['base_url'] url = f"https://{ns}.{base_url}/" - t_headers = {"x-mcn-namespace": ns,"x-mcn-src-site": app.config["ce_info"]["site_name"]} + t_headers = { "x-mcn-namespace": ns, "x-mcn-src-site": app.config["ce_info"]["site_name"]} r_data = cloudapp_req_headers(s, url, 7, t_headers) return jsonify(status='success', data=r_data) except (LabException, requests.RequestException, ValueError) as e: diff --git a/labapp/app/fetch.py b/labapp/app/fetch.py index 282ebe3..d881f64 100644 --- a/labapp/app/fetch.py +++ b/labapp/app/fetch.py @@ -1,3 +1,5 @@ +from requests.structures import CaseInsensitiveDict + def headers_cleaner(headers): """ Remove headers that contain specific substrings. @@ -34,9 +36,11 @@ def cloudapp_req_headers(session, url, timeout, headers): response = session.get(url, timeout=timeout) response.raise_for_status() data = response.json() + req_headers = CaseInsensitiveDict(data['request_headers']) print(data) for header in headers: - if header.lower() not in data['request_headers']: + head_value = req_headers.get(header) + if not head_value: raise ValueError(f"Header {header} not found request headers.") clean_headers = headers_cleaner(data['request_headers']) data['request_headers'] = clean_headers