File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -135,6 +135,8 @@ pub struct HttpServerConfig {
135135 pub server_metrics_port : String ,
136136 #[ serde( default = "default_auth_config" ) ]
137137 pub auth : AuthConfig ,
138+ #[ serde( default = "default_timeout_seconds" ) ]
139+ pub timeout_seconds : u64 ,
138140}
139141
140142#[ cfg( feature = "http" ) ]
@@ -145,6 +147,7 @@ impl Default for HttpServerConfig {
145147 connection_url : default_connection_url ( ) ,
146148 server_metrics_port : default_server_metrics_port ( ) ,
147149 auth : default_auth_config ( ) ,
150+ timeout_seconds : default_timeout_seconds ( ) ,
148151 }
149152 }
150153}
@@ -241,6 +244,11 @@ fn default_auth_config() -> AuthConfig {
241244 AuthConfig :: default ( )
242245}
243246
247+ #[ cfg( feature = "http" ) ]
248+ fn default_timeout_seconds ( ) -> u64 {
249+ 10
250+ }
251+
244252pub fn create_config ( config_path : PathBuf ) -> AppConfig {
245253 if config_path. exists ( ) {
246254 debug ! ( "Config exists" ) ;
Original file line number Diff line number Diff line change @@ -69,14 +69,19 @@ pub struct HttpApp {
6969
7070impl HttpApp {
7171 /// create a new app for the flightsql server
72- pub async fn try_new ( execution : AppExecution , addr : & str , metrics_addr : & str ) -> Result < Self > {
72+ pub async fn try_new (
73+ execution : AppExecution ,
74+ config : AppConfig ,
75+ addr : & str ,
76+ metrics_addr : & str ,
77+ ) -> Result < Self > {
7378 info ! ( "Listening to HTTP on {addr}" ) ;
7479 let listener = TcpListener :: bind ( addr) . await . unwrap ( ) ;
7580
7681 // prepare the shutdown channel
7782 let state = execution. execution_ctx ( ) . clone ( ) ;
7883
79- let router = create_router ( state) ;
84+ let router = create_router ( state, config . http_server ) ;
8085
8186 let metrics_addr: SocketAddr = metrics_addr. parse ( ) ?;
8287 try_start_metrics_server ( metrics_addr) ?;
@@ -114,6 +119,7 @@ pub async fn try_run(cli: DftArgs, config: AppConfig) -> Result<()> {
114119 let app_execution = AppExecution :: new ( execution_ctx) ;
115120 let app = HttpApp :: try_new (
116121 app_execution,
122+ config. clone ( ) ,
117123 & cli. host . unwrap_or ( DEFAULT_SERVER_ADDRESS . to_string ( ) ) ,
118124 & config. http_server . server_metrics_port ,
119125 )
Original file line number Diff line number Diff line change @@ -31,20 +31,22 @@ use log::error;
3131use tokio_stream:: StreamExt ;
3232use tower_http:: { timeout:: TimeoutLayer , trace:: TraceLayer } ;
3333
34- const DEFAULT_TIMEOUT_SECONDS : u64 = 10 ;
34+ use crate :: config :: HttpServerConfig ;
3535
36- pub fn create_router ( execution : ExecutionContext ) -> Router {
36+ pub fn create_router ( execution : ExecutionContext , config : HttpServerConfig ) -> Router {
3737 Router :: new ( )
3838 . route (
3939 "/" ,
4040 get ( |State ( _) : State < ExecutionContext > | async { "Hello, from DFT!" } ) ,
4141 )
4242 . route ( "/sql" , get ( execute_sql) )
43+ . route ( "/catalog" , get ( execute_sql) )
44+ . route ( "/{catalog}/{schema}/{table}" , get ( execute_sql) )
4345 . layer ( (
4446 TraceLayer :: new_for_http ( ) ,
4547 // Graceful shutdown will wait for outstanding requests to complete. Add a timeout so
4648 // requests don't hang forever.
47- TimeoutLayer :: new ( Duration :: from_secs ( DEFAULT_TIMEOUT_SECONDS ) ) ,
49+ TimeoutLayer :: new ( Duration :: from_secs ( config . timeout_seconds ) ) ,
4850 ) )
4951 . with_state ( execution)
5052}
You can’t perform that action at this time.
0 commit comments