def extract_ct_body(params: Dict[str, List[str]]) -> Tuple[str, bytes]: """ Extract the content type and body from a list of get parameters. :param params: A dictionary of key/value of parameters as provided by urllib.parse.parse_qs :return: a tuple that contains a string and bytes, respectively ct and body. :raises: a DOHParamsException with an explanatory message. """ if constants.DOH_CONTENT_TYPE_PARAM in params and \ len(params[constants.DOH_CONTENT_TYPE_PARAM]): ct = params[constants.DOH_CONTENT_TYPE_PARAM][0] if not ct: # An empty value indicates the default # application/dns-udpwireformat type ct = constants.DOH_MEDIA_TYPE else: raise server_protocol.DOHParamsException( b'Missing Content Type Parameter') if constants.DOH_DNS_PARAM in params and \ len(params[constants.DOH_DNS_PARAM]): try: body = doh_b64_decode(params[constants.DOH_DNS_PARAM][0]) except binascii.Error: raise server_protocol.DOHParamsException(b'Invalid Body Parameter') if not body: raise server_protocol.DOHParamsException(b'Missing Body') else: raise server_protocol.DOHParamsException(b'Missing Body Parameter') return ct, body
def extract_ct_body(params: Dict[str, List[str]]) -> Tuple[str, bytes]: """ Extract the content type and body from a list of get parameters. :param params: A dictionary of key/value of parameters as provided by urllib.parse.parse_qs :return: a tuple that contains a string and bytes, respectively ct and body. :raises: a DOHParamsException with an explanatory message. """ ct = constants.DOH_MEDIA_TYPE if constants.DOH_DNS_PARAM in params and len( params[constants.DOH_DNS_PARAM]): try: body = doh_b64_decode(params[constants.DOH_DNS_PARAM][0]) except binascii.Error: raise server_protocol.DOHParamsException(b"Invalid Body Parameter") if not body: raise server_protocol.DOHParamsException(b"Missing Body") else: raise server_protocol.DOHParamsException(b"Missing Body Parameter") return ct, body