import re # RegEx def extract_header(payload): try: header_brut = payload[:payload.index(b"\r\n\r\n") + 2] except ValueError: return None header = dict(re.findall( r"(?P.*?): (?P.*?)\r\n", header_brut.decode(errors="ignore") )) if "Content-Type" not in header: return None return header