Skip to content

Instantly share code, notes, and snippets.

@eupendra
Created December 11, 2020 09:49
Show Gist options
  • Save eupendra/b04beda4352c2e6b63693dbdcb1c1fbc to your computer and use it in GitHub Desktop.
Save eupendra/b04beda4352c2e6b63693dbdcb1c1fbc to your computer and use it in GitHub Desktop.
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