From 7de57cb6805cd2b9ab2bfaa2a21f83a6212b83a9 Mon Sep 17 00:00:00 2001 From: spl0k Date: Sun, 29 Oct 2017 16:00:39 +0100 Subject: [PATCH] Small API content-type and error codes adjustments --- supysonic/api/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/supysonic/api/__init__.py b/supysonic/api/__init__.py index 84718da..c9379ca 100644 --- a/supysonic/api/__init__.py +++ b/supysonic/api/__init__.py @@ -40,7 +40,7 @@ def set_formatter(): if not callback and request.endpoint not in [ 'stream_media', 'cover_art' ]: return ResponseHelper.responsize_json({ 'error': { - 'code': 0, + 'code': 10, 'message': 'Missing callback' } }, error = True), 400 @@ -113,7 +113,13 @@ def set_headers(response): if response.mimetype.startswith('text'): f = request.values.get('f') - response.headers['Content-Type'] = 'application/json' if f in [ 'jsonp', 'json' ] else 'text/xml' + # TODO set the mimetype when creating the response, here we could lose some info + if f == 'json': + response.headers['Content-Type'] = 'application/json' + elif f == 'jsonp': + response.headers['Content-Type'] = 'application/javascript' + else: + response.headers['Content-Type'] = 'text/xml' response.headers['Access-Control-Allow-Origin'] = '*'