44
55content_type_mapping = {
66 "application/json" : Jsoner ,
7- "application/json; charset=utf-8" : Jsoner ,
87 "text/csv" : None ,
98 "text/plain" : None ,
109 # image types
3938
4039class ContentType :
4140 @staticmethod
42- def get_deserializer (content_type ):
43- if content_type in content_type_mapping :
44- return content_type_mapping [content_type ]
41+ def get_deserializer (content_type : str ):
42+ # Extract media type from content type
43+ extracted = content_type .split (";" )[0 ]
44+ if extracted in content_type_mapping :
45+ return content_type_mapping [extracted ]
4546 else :
4647 message = f"""
4748 Content type "{ content_type } " not supported.
@@ -51,13 +52,15 @@ def get_deserializer(content_type):
5152 raise Exception (message )
5253
5354 @staticmethod
54- def get_serializer (accept ):
55- if accept in content_type_mapping :
56- return content_type_mapping [accept ]
57- else :
58- message = f"""
59- Accept type "{ accept } " not supported.
60- Supported accept types are:
61- { ", " .join (list (content_type_mapping .keys ()))}
62- """
63- raise Exception (message )
55+ def get_serializer (accept : str ):
56+ extracts = accept .split ("," )
57+ for extract in extracts :
58+ extracted = extract .split (";" )[0 ]
59+ if extracted in content_type_mapping :
60+ return content_type_mapping [extracted ]
61+ message = f"""
62+ Accept type "{ accept } " not supported.
63+ Supported accept types are:
64+ { ", " .join (list (content_type_mapping .keys ()))}
65+ """
66+ raise Exception (message )
0 commit comments