Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set http response chartset to utf-8 when using table format #3571

Merged
merged 1 commit into from Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/servers/src/http/table_result.rs
Expand Up @@ -135,7 +135,7 @@ impl IntoResponse for TableResponse {
let mut resp = (
[(
header::CONTENT_TYPE,
HeaderValue::from_static(mime::PLAIN.as_ref()),
HeaderValue::from_static(mime::TEXT_PLAIN_UTF_8.as_ref()),
)],
self.to_string(),
)
Expand Down
40 changes: 37 additions & 3 deletions src/servers/tests/http/http_handler_test.rs
Expand Up @@ -46,7 +46,7 @@ async fn test_sql_not_provided() {
script_handler: None,
};

for format in ["greptimedb_v1", "influxdb_v1", "csv"] {
for format in ["greptimedb_v1", "influxdb_v1", "csv", "table"] {
let query = http_handler::SqlQuery {
db: None,
sql: None,
Expand Down Expand Up @@ -82,7 +82,7 @@ async fn test_sql_output_rows() {
script_handler: None,
};

for format in ["greptimedb_v1", "influxdb_v1", "csv"] {
for format in ["greptimedb_v1", "influxdb_v1", "csv", "table"] {
let query = create_query(format);
let json = http_handler::sql(
State(api_state.clone()),
Expand Down Expand Up @@ -154,6 +154,23 @@ async fn test_sql_output_rows() {
hyper::body::Bytes::from_static(b"4950\n"),
);
}
HttpResponse::Table(resp) => {
use http_body::Body as HttpBody;
let mut resp = resp.into_response();
assert_eq!(
resp.headers().get(header::CONTENT_TYPE),
Some(HeaderValue::from_static(mime::TEXT_PLAIN_UTF_8.as_ref())).as_ref(),
);
assert_eq!(
resp.body_mut().data().await.unwrap().unwrap(),
hyper::body::Bytes::from(
r#"┌─SUM(numbers.uint32s)─┐
│ 4950 │
└──────────────────────┘
"#
),
);
}
_ => unreachable!(),
}
}
Expand All @@ -172,7 +189,7 @@ async fn test_sql_form() {
script_handler: None,
};

for format in ["greptimedb_v1", "influxdb_v1", "csv"] {
for format in ["greptimedb_v1", "influxdb_v1", "csv", "table"] {
let form = create_form(format);
let json = http_handler::sql(
State(api_state.clone()),
Expand Down Expand Up @@ -244,6 +261,23 @@ async fn test_sql_form() {
hyper::body::Bytes::from_static(b"4950\n"),
);
}
HttpResponse::Table(resp) => {
use http_body::Body as HttpBody;
let mut resp = resp.into_response();
assert_eq!(
resp.headers().get(header::CONTENT_TYPE),
Some(HeaderValue::from_static(mime::TEXT_PLAIN_UTF_8.as_ref())).as_ref(),
);
assert_eq!(
resp.body_mut().data().await.unwrap().unwrap(),
hyper::body::Bytes::from(
r#"┌─SUM(numbers.uint32s)─┐
│ 4950 │
└──────────────────────┘
"#
),
);
}
_ => unreachable!(),
}
}
Expand Down