@@ -31,6 +31,7 @@ use databend_common_expression::DataSchema;
3131use databend_common_management:: WorkloadGroupResourceManager ;
3232use databend_common_metrics:: http:: metrics_incr_http_response_errors_count;
3333use fastrace:: prelude:: * ;
34+ use headers:: Header ;
3435use http:: HeaderMap ;
3536use http:: HeaderValue ;
3637use http:: StatusCode ;
@@ -499,13 +500,16 @@ async fn query_page_handler(
499500
500501#[ poem:: handler]
501502#[ async_backtrace:: framed]
502- #[ fastrace:: trace]
503503pub ( 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