This repository has been archived on 2023-07-16. You can view files and clone it, but cannot push or open issues or pull requests.
hackaday.io-spambot-hunter/hadsh/util.py
Stuart Longland 6eb99f2653
hadapi, util: Re-locate body parsing
We'll need it in the server for requesting POST/PUT bodies too.
2018-01-07 16:55:32 +10:00

13 lines
417 B
Python

from cgi import parse_header
def decode_body(content_type, body_data, default_encoding='UTF-8'):
"""
Decode a given reponse body.
"""
# Ideally, encoding should be in the content type
(ct, ctopts) = parse_header(content_type)
encoding = ctopts.get('charset', default_encoding)
# Return the decoded payload along with the content-type.
return (ct, ctopts, body_data.decode(encoding))