Skip to content

Commit

Permalink
Warcserver / CDXJ API: properly handle unsupported output formats (#623)
Browse files Browse the repository at this point in the history
- add unit test to verify unknown output formats are handled
  if output fields param is in request
  • Loading branch information
sebastian-nagel committed Apr 27, 2021
1 parent 4224cdd commit c62b1bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pywb/warcserver/handlers.py
Expand Up @@ -86,7 +86,7 @@ def __call__(self, params):
if fields and isinstance(fields, str):
fields = fields.split(',')

handler = self.OUTPUTS.get(output, fields)
handler = self.OUTPUTS.get(output)
if not handler:
errs = dict(last_exc=BadRequestException('output={0} not supported'.format(output)))
return None, None, errs
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cdx_server_app.py
Expand Up @@ -287,5 +287,13 @@ def test_collapseTime_resolveRevisits_reverse(self):
for i in range(len(cdxes) - 1):
assert cdxes[i]['timestamp'] >= cdxes[i + 1]['timestamp']

def test_error_unknown_output_format(self):
"""test unknown output format in combination with a list of output fields"""
resp = self.query('http://www.iana.org/_css/2013.1/print.css',
is_error=True,
fields='urlkey,timestamp,status',
output='foo')
assert resp.status_code == 400
assert resp.json == {'message': 'output=foo not supported'}


0 comments on commit c62b1bc

Please sign in to comment.