Skip to content

Instantly share code, notes, and snippets.

@eupendra
Created April 24, 2020 04:28
Show Gist options
  • Save eupendra/a898aaaac71ac855a63ba9498dfa5048 to your computer and use it in GitHub Desktop.
Save eupendra/a898aaaac71ac855a63ba9498dfa5048 to your computer and use it in GitHub Desktop.
def get_headers(s, sep=': ', strip_cookie=True,strip_cl=True, strip_headers:list=[]) -> dict():
l = s.split('\n')
d = dict()
for kv in l:
if kv:
k = kv.split(sep)[0]
v = kv.split(sep)[1]
if strip_cookie and k == 'cookie': continue
if strip_cl and k == '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