diff --git a/shinysdr/i/db.py b/shinysdr/i/db.py index dced2696..21f364f1 100644 --- a/shinysdr/i/db.py +++ b/shinysdr/i/db.py @@ -227,7 +227,7 @@ def render_GET(self, request): return json.dumps(self.__record).encode('utf-8') def render_POST(self, request): - assert request.getHeader(b'Content-Type') == b'application/json; charset=utf-8' + assert request.getHeader(b'Content-Type') in (b'application/json', b'application/json; charset=utf-8') if not self.__database.writable: request.setResponseCode(http.FORBIDDEN) request.setHeader(b'Content-Type', b'text/plain') diff --git a/shinysdr/i/test_db.py b/shinysdr/i/test_db.py index a536ac51..a2b2264e 100644 --- a/shinysdr/i/test_db.py +++ b/shinysdr/i/test_db.py @@ -290,7 +290,7 @@ def test_index_common(self): @defer.inlineCallbacks def test_index_response(self): response, data = yield http_get(reactor, self.__url('/')) - self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json']) + self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json; charset=utf-8']) j = json.loads(data) self.assertEqual(j, self.response_json) @@ -300,7 +300,7 @@ def test_record_common(self): @defer.inlineCallbacks def test_record_response(self): response, data = yield http_get(reactor, self.__url('/1')) - self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json']) + self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json; charset=utf-8']) j = json.loads(data) self.assertEqual(j, self.test_records[1]) diff --git a/shinysdr/testutil.py b/shinysdr/testutil.py index 9ab50b91..9b6ef28b 100644 --- a/shinysdr/testutil.py +++ b/shinysdr/testutil.py @@ -505,7 +505,7 @@ def _assert_http_response_properties(test_case, response, data): if data is not None: # not a HEAD request content_type = response.headers.getRawHeaders(b'Content-Type')[0] - if content_type == 'application/json': + if content_type in ('application/json', 'application/json; charset=utf-8'): json.loads(data) # raises error if it doesn't parse elif content_type.startswith('text/html'): test_case.assertRegex(content_type, r'(?i)text/html;\s*charset=utf-8')