Files
live-campus-mcs-p-2027.2/Semaine_09/Scapy_test/extract_header.py
T
gauvainboiche ce1f0e513a feat: Semaine 9
2026-05-15 16:24:56 +02:00

16 lines
372 B
Python

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<cle>.*?): (?P<valeur>.*?)\r\n",
header_brut.decode(errors="ignore")
))
if "Content-Type" not in header:
return None
return header