Skip to content

Commit

Permalink
interesting
Browse files Browse the repository at this point in the history
  • Loading branch information
kreynoldsf5 committed May 2, 2024
1 parent d5eeb0e commit 83fea2b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion labapp/app/fetch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from requests.structures import CaseInsensitiveDict

def headers_cleaner(headers):
"""
Remove headers that contain specific substrings.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 83fea2b

Please sign in to comment.