You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/06/02 00:59:04 UTC

(superset) branch fix/response-content-type-charset created (now 49e590d22a7)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a change to branch fix/response-content-type-charset
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 49e590d22a7 fix: set charset via content_type to avoid malformed Content-Type headers

This branch includes the following new commits:

     new 49e590d22a7 fix: set charset via content_type to avoid malformed Content-Type headers

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: fix: set charset via content_type to avoid malformed Content-Type headers

Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch fix/response-content-type-charset
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 49e590d22a796437992a0cebcd78b12a61fa7c5f
Author: Claude Code <no...@anthropic.com>
AuthorDate: Mon Jun 1 17:58:07 2026 -0700

    fix: set charset via content_type to avoid malformed Content-Type headers
    
    Two Content-Type construction issues:
    
    - The streaming CSV export passed mimetype=f"text/csv; charset={encoding}" to
      Flask's Response. Werkzeug appends a default charset to the mimetype, so a
      charset embedded there produces a doubled, malformed header
      (text/csv; charset=utf-8; charset=utf-8). Use content_type= instead, which is
      taken verbatim.
    - json_success and BaseSupersetView.json_response returned application/json
      without a charset, inconsistent with _send_chart_response. Set
      content_type="application/json; charset=utf-8".
    
    Update the form_data content-type assertion accordingly.
    
    Co-Authored-By: Claude Opus 4.8 <no...@anthropic.com>
---
 superset/charts/data/api.py                 | 5 ++++-
 superset/views/base.py                      | 6 ++++--
 tests/integration_tests/charts/api_tests.py | 2 +-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/superset/charts/data/api.py b/superset/charts/data/api.py
index 3b6fd48b4fe..1f26a2dd7aa 100644
--- a/superset/charts/data/api.py
+++ b/superset/charts/data/api.py
@@ -747,7 +747,10 @@ class ChartDataRestApi(ChartRestApi):
         # Create response with streaming headers
         response = Response(
             csv_generator_callable(),  # Call the callable to get generator
-            mimetype=f"text/csv; charset={encoding}",
+            # Use content_type (not mimetype) so the charset is set verbatim;
+            # passing a charset via mimetype makes Werkzeug append a second
+            # charset, producing a malformed doubled Content-Type header.
+            content_type=f"text/csv; charset={encoding}",
             headers={
                 "Content-Disposition": f'attachment; filename="{filename}"',
                 "Cache-Control": "no-cache",
diff --git a/superset/views/base.py b/superset/views/base.py
index 7947b57045e..b55f84bf3b4 100644
--- a/superset/views/base.py
+++ b/superset/views/base.py
@@ -141,7 +141,9 @@ def get_error_msg() -> str:
 
 
 def json_success(json_msg: str, status: int = 200) -> FlaskResponse:
-    return Response(json_msg, status=status, mimetype="application/json")
+    return Response(
+        json_msg, status=status, content_type="application/json; charset=utf-8"
+    )
 
 
 def data_payload_response(payload_json: str, has_error: bool = False) -> FlaskResponse:
@@ -214,7 +216,7 @@ class BaseSupersetView(BaseView):
         return Response(
             json.dumps(obj, default=json.json_int_dttm_ser, ignore_nan=True),
             status=status,
-            mimetype="application/json",
+            content_type="application/json; charset=utf-8",
         )
 
     def render_app_template(
diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py
index 699a126f6b8..ea2b1de1eac 100644
--- a/tests/integration_tests/charts/api_tests.py
+++ b/tests/integration_tests/charts/api_tests.py
@@ -1765,7 +1765,7 @@ class TestChartApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCase):
         rv = self.client.get(uri)
         data = json.loads(rv.data.decode("utf-8"))
         assert rv.status_code == 200
-        assert rv.content_type == "application/json"
+        assert rv.content_type == "application/json; charset=utf-8"
         if slice:
             assert data["slice_id"] == slice.id