What does ":" and "+2" mean in [:http_payload.index("\r\n\r\n")+2]
?
What does "("/")" and "[1]" mean in .split("/")[1]
?
def get_http_headers(http_payload):
try:
# split the headers off if it is HTTP traffic
headers_raw = http_payload[:http_payload.index("\r\n\r\n")+2]
# break out the headers
headers = dict(re.findall(r"(?P<name>.*?): (? P<value>.*?)\r\n", headers_raw))
except:
return None
return headers
def extract_image(headers, http_payload):
image = None
image_type = None
try:
if "image" in headers["Content-Type"]:
# grab the image type and image body
image_type = headers["Content-Type"].split("/")[1]
image = http_payload[http_payload.index("\r\n\r\n")+4:]
except:
pass
except:
return None, None
return image, image_type