Backport of opensearch-project#1779 to 1.3.
The SQL/PPL REST handlers hardcode the response Content-Type to
"application/json" for every format, including format=csv and
format=raw whose bodies are plain text. Downstream clients that trust
the Content-Type header (e.g. OpenSearch Dashboards' legacy client used
by Query Workbench) then attempt to JSON-parse the CSV/raw body, which
fails and surfaces as an HTTP 400 to the user even though the data is
correct.
Add ResponseFormatter#contentType(): FlatResponseFormatter (CSV/RAW)
returns "plain/text; charset=UTF-8" and JsonResponseFormatter (JDBC/
JSON) returns "application/json; charset=UTF-8". Thread the formatter's
content type through RestSQLQueryAction so each format returns the
correct header. JDBC/JSON responses are unchanged.
Verified on a local OpenSearch 1.3.2 cluster: format=csv/raw now return
plain/text (200) and the Query Workbench CSV/Text download tests pass
(previously 400).
Description
Backport of #1779 to the
1.3line.The SQL/PPL REST handlers hardcode the response
Content-Typetoapplication/jsonfor every format, includingformat=csvandformat=rawwhose bodies are plain text. Clients that trust theContent-Typeheader — notably the OpenSearch Dashboards legacy client used by Query Workbench — then try toJSON.parsethe CSV/raw body, which throws a serialization error and surfaces to the user as an HTTP 400 even though the returned data is correct.Change
ResponseFormatter#contentType().FlatResponseFormatter(CSV/RAW) returnsplain/text; charset=UTF-8;JsonResponseFormatter(JDBC/JSON) returnsapplication/json; charset=UTF-8.formatter.contentType()throughRestSQLQueryAction#sendResponseso each format returns the correct header. JDBC/JSON responses are unchanged.Verification (local OpenSearch 1.3.2)
POST /_plugins/_sql?format=csv200application/json200plain/textPOST /_plugins/_sql?format=raw200application/json200plain/textformat=jsonapplication/jsonapplication/json(unchanged)Full loop: repointed a local OpenSearch Dashboards Query Workbench at the patched cluster — the Download and verify CSV and Download and verify Text Cypress tests now pass (previously failed with 400).