Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 6c309ec

Browse files
committed
when more than one Content-Type is recommended try to make a good choice
1 parent bf93a19 commit 6c309ec

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

CloudFlare/cloudflare.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,24 @@ def _add_headers(self, method, data, files, content_type=None):
8080
ct = content_type[method]
8181
if isinstance(ct, list):
8282
# How do we choose from more than one content type?
83+
found = False
8384
for t in ct:
84-
# we have to match against the data type - arggg! how? XXX/TODO - use first for now
85-
self.headers['Content-Type'] = t
86-
break
85+
# we have to match against the data type - arggg!
86+
if 'application/octet-stream' == t and isinstance(data, (bytes,bytearray)):
87+
self.headers['Content-Type'] = t
88+
found = True
89+
break
90+
if 'application/json' == t and isinstance(data, (list,dict)):
91+
self.headers['Content-Type'] = t
92+
found = True
93+
break
94+
if 'application/javascript' == t and isinstance(data, str):
95+
self.headers['Content-Type'] = t
96+
found = True
97+
break
98+
if not found:
99+
# punt - pick first - we can't do anything else!
100+
self.headers['Content-Type'] = ct[0]
87101
else:
88102
self.headers['Content-Type'] = ct
89103
else:

0 commit comments

Comments
 (0)