Skip to content

Commit ffc55a9

Browse files
committed
Prevent crash when clients do not set accept header. Use
__default_accept_type if not specified.
1 parent 16d53a6 commit ffc55a9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

roundup/rest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ def parse_accept_header(accept):
203203
# https://github.com/martinblech/mimerender
204204
"""
205205
result = []
206+
if not accept:
207+
return result
208+
206209
for media_range in accept.split(","):
207210
parts = media_range.split(";")
208211
media_type = parts.pop(0).strip()
@@ -1653,10 +1656,9 @@ def dispatch(self, method, uri, input):
16531656
'Ignoring X-HTTP-Method-Override using %s request on %s',
16541657
method.upper(), uri)
16551658

1656-
16571659
# parse Accept header and get the content type
16581660
accept_header = parse_accept_header(headers.get('Accept'))
1659-
accept_type = "invalid"
1661+
accept_type = self.__default_accept_type
16601662
for part in accept_header:
16611663
if part[0] in self.__accepted_content_type:
16621664
accept_type = self.__accepted_content_type[part[0]]
@@ -1687,7 +1689,7 @@ def dispatch(self, method, uri, input):
16871689
# header (Accept: application/json, application/xml)
16881690
# default (application/json)
16891691
ext_type = os.path.splitext(urlparse(uri).path)[1][1:]
1690-
data_type = ext_type or accept_type or self.__default_accept_type
1692+
data_type = ext_type or accept_type
16911693

16921694
if ( ext_type ):
16931695
# strip extension so uri make sense

0 commit comments

Comments
 (0)