Fixing Header Parsing Issue in Python: Troubleshooting Name-Value Assignment
The code it is failing at is this :
def parse_env_headers(s: str) -> Dict[str, str]:
"""
Parse ``s``, which is a ``str`` instance containing HTTP headers encoded
for use in ENV variables per the W3C Baggage HTTP header format at
https://www.w3.org/TR/baggage/#baggage-http-header-format, except that
additional semi-colon delimited metadata is not supported.
If the headers are not urlencoded, we will log a warning and attempt to urldecode them.
"""
headers: Dict[str, str] = {}
headers_list: List[str] = _DELIMITER_PATTERN.split(s)
for header in headers_list:
print(header)
if not header: # empty string
continue
match = _HEADER_PATTERN.fullmatch(header.strip())
if not match:
parts = header.split("=", 1)
print(parts)
name, value = parts
print(name, value)
encoded_header = f"{urllib.parse.quote(name)}={urllib.parse.quote(value)}"
match = _HEADER_PATTERN.fullmatch(encoded_header.strip())
if not match:
logger.warning(
"Header format invalid! Header values in environment variables must be "
"URL encoded: %s",
f"{name}: ****",
)
continue
logger.warning(
"Header values in environment variables should be URL encoded, attempting to "
"URL encode header: {name}: ****"
)
name, value = header.split("=", 1)
name = urllib.parse.unquote(name).strip().lower()
value = urllib.parse.unquote(value).strip()
headers[name] = value
return headers
Specifically on the part when it tries to assign name, value from parts variablle.
