Skip to content

Commit 576bc28

Browse files
committed
BodyFormat
1 parent 8acd706 commit 576bc28

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/query/service/src/servers/http/v1/http_query_handlers.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use databend_common_expression::DataSchema;
3131
use databend_common_management::WorkloadGroupResourceManager;
3232
use databend_common_metrics::http::metrics_incr_http_response_errors_count;
3333
use fastrace::prelude::*;
34+
use headers::Header;
3435
use http::HeaderMap;
3536
use http::HeaderValue;
3637
use http::StatusCode;
@@ -499,13 +500,16 @@ async fn query_page_handler(
499500

500501
#[poem::handler]
501502
#[async_backtrace::framed]
502-
#[fastrace::trace]
503503
pub(crate) async fn query_handler(
504504
ctx: &HttpQueryContext,
505505
Json(mut req): Json<HttpQueryRequest>,
506506
) -> PoemResult<impl IntoResponse> {
507507
let session = ctx.session.clone();
508508

509+
// poem::http::Request
510+
511+
// poem::web::TypedHeader;
512+
509513
let query_handle = async {
510514
let agent_info = ctx
511515
.user_agent
@@ -940,3 +944,36 @@ pub(crate) fn get_http_tracing_span(
940944
Span::root(name, SpanContext::new(trace_id, SpanId(rand::random())))
941945
.with_properties(|| ctx.to_fastrace_properties())
942946
}
947+
948+
enum BodyFormat {
949+
Json,
950+
Arrow,
951+
}
952+
953+
impl Header for BodyFormat {
954+
fn name() -> &'static http::HeaderName {
955+
&http::header::ACCEPT
956+
}
957+
958+
fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error>
959+
where
960+
Self: Sized,
961+
I: Iterator<Item = &'i HeaderValue>,
962+
{
963+
if let Some(v) = values.next() {
964+
match v.to_str() {
965+
Ok("application/vnd.apache.arrow.file") => return Ok(BodyFormat::Arrow),
966+
Err(_) => return Err(headers::Error::invalid()),
967+
_ => {}
968+
};
969+
}
970+
Ok(BodyFormat::Json)
971+
}
972+
973+
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E) {
974+
values.extend([match self {
975+
BodyFormat::Json => HeaderValue::from_static("application/json"),
976+
BodyFormat::Arrow => HeaderValue::from_static("application/vnd.apache.arrow.file"),
977+
}]);
978+
}
979+
}

0 commit comments

Comments
 (0)