Created
December 11, 2020 09:49
-
-
Save eupendra/b04beda4352c2e6b63693dbdcb1c1fbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_headers(s, sep=': ', strip_cookie=True, strip_cl=True, strip_headers: list = []) -> dict(): | |
d = dict() | |
for kv in s.split('\n'): | |
kv = kv.strip() | |
if kv and sep in kv: | |
v='' | |
k = kv.split(sep)[0] | |
if len(kv.split(sep)) == 1: | |
v = '' | |
else: | |
v = kv.split(sep)[1] | |
if v == '\'\'': | |
v ='' | |
# v = kv.split(sep)[1] | |
if strip_cookie and k.lower() == 'cookie': continue | |
if strip_cl and k.lower() == 'content-length': continue | |
if k in strip_headers: continue | |
d[k] = v | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment