@@ -201,6 +201,43 @@ fn sdk_base_path(api_url: &str) -> String {
201201 trimmed. strip_suffix ( "/v1" ) . unwrap_or ( trimmed) . to_string ( )
202202}
203203
204+ /// Apply the seam's common request headers to a raw `RequestBuilder`: User-Agent,
205+ /// the `X-Workspace-Id` api_key, the sandbox `X-Session-Id` and database
206+ /// `X-Database-Id` scope, and the resolved bearer. Generated SDK ops inject the
207+ /// api_key headers themselves; the raw seam helpers ([`Api::get_json`] etc.)
208+ /// bypass the generated client, so they funnel through this one place rather
209+ /// than repeating the block per verb.
210+ async fn apply_seam_headers (
211+ mut req : reqwest013:: RequestBuilder ,
212+ cfg : & Configuration ,
213+ session_id : Option < & str > ,
214+ database_id : Option < & str > ,
215+ ) -> reqwest013:: RequestBuilder {
216+ if let Some ( ref user_agent) = cfg. user_agent {
217+ req = req. header ( reqwest:: header:: USER_AGENT , user_agent. clone ( ) ) ;
218+ }
219+ if let Some ( apikey) = cfg. api_keys . get ( hotdata:: client:: WORKSPACE_ID_HEADER ) {
220+ let value = match apikey. prefix {
221+ Some ( ref prefix) => format ! ( "{} {}" , prefix, apikey. key) ,
222+ None => apikey. key . clone ( ) ,
223+ } ;
224+ req = req. header ( hotdata:: client:: WORKSPACE_ID_HEADER , value) ;
225+ }
226+ // Sandbox session scope (also forwarded from api_keys on generated ops).
227+ if let Some ( sid) = session_id {
228+ req = req. header ( "X-Session-Id" , sid) ;
229+ }
230+ // Database scope — generated ops don't forward it, so the seam must
231+ // (e.g. `hotdata query --database`).
232+ if let Some ( db) = database_id {
233+ req = req. header ( "X-Database-Id" , db) ;
234+ }
235+ if let Some ( token) = cfg. resolve_bearer_token ( ) . await {
236+ req = req. bearer_auth ( token) ;
237+ }
238+ req
239+ }
240+
204241impl Api {
205242 /// Build an [`Api`], reproducing `ApiClient::new`'s auth-source precedence
206243 /// by selecting the [`AuthMode`] the installed provider will serve. Exits
@@ -491,30 +528,7 @@ impl Api {
491528 if !query. is_empty ( ) {
492529 req = req. query ( query) ;
493530 }
494- if let Some ( ref user_agent) = cfg. user_agent {
495- req = req. header ( reqwest:: header:: USER_AGENT , user_agent. clone ( ) ) ;
496- }
497- if let Some ( apikey) = cfg. api_keys . get ( hotdata:: client:: WORKSPACE_ID_HEADER ) {
498- let value = match apikey. prefix {
499- Some ( ref prefix) => format ! ( "{} {}" , prefix, apikey. key) ,
500- None => apikey. key . clone ( ) ,
501- } ;
502- req = req. header ( hotdata:: client:: WORKSPACE_ID_HEADER , value) ;
503- }
504- // Sandbox session scope (also forwarded from api_keys on generated
505- // ops; set here for the raw seam paths).
506- if let Some ( ref sid) = session_id {
507- req = req. header ( "X-Session-Id" , sid. clone ( ) ) ;
508- }
509- // X-Database-Id scopes the request to a database. The old ApiClient
510- // attached it to every request when set; the SDK does not forward
511- // it, so the seam must (e.g. `hotdata query --database`).
512- if let Some ( ref db) = database_id {
513- req = req. header ( "X-Database-Id" , db. clone ( ) ) ;
514- }
515- if let Some ( token) = cfg. resolve_bearer_token ( ) . await {
516- req = req. bearer_auth ( token) ;
517- }
531+ req = apply_seam_headers ( req, cfg, session_id. as_deref ( ) , database_id. as_deref ( ) ) . await ;
518532
519533 let resp = req
520534 . send ( )
@@ -552,30 +566,7 @@ impl Api {
552566 let session_id = self . session_id . clone ( ) ;
553567 rt ( ) . block_on ( async move {
554568 let mut req = cfg. client . request ( reqwest:: Method :: POST , & url) . json ( body) ;
555- if let Some ( ref user_agent) = cfg. user_agent {
556- req = req. header ( reqwest:: header:: USER_AGENT , user_agent. clone ( ) ) ;
557- }
558- if let Some ( apikey) = cfg. api_keys . get ( hotdata:: client:: WORKSPACE_ID_HEADER ) {
559- let value = match apikey. prefix {
560- Some ( ref prefix) => format ! ( "{} {}" , prefix, apikey. key) ,
561- None => apikey. key . clone ( ) ,
562- } ;
563- req = req. header ( hotdata:: client:: WORKSPACE_ID_HEADER , value) ;
564- }
565- // Sandbox session scope (also forwarded from api_keys on generated
566- // ops; set here for the raw seam paths).
567- if let Some ( ref sid) = session_id {
568- req = req. header ( "X-Session-Id" , sid. clone ( ) ) ;
569- }
570- // X-Database-Id scopes the request to a database. The old ApiClient
571- // attached it to every request when set; the SDK does not forward
572- // it, so the seam must (e.g. `hotdata query --database`).
573- if let Some ( ref db) = database_id {
574- req = req. header ( "X-Database-Id" , db. clone ( ) ) ;
575- }
576- if let Some ( token) = cfg. resolve_bearer_token ( ) . await {
577- req = req. bearer_auth ( token) ;
578- }
569+ req = apply_seam_headers ( req, cfg, session_id. as_deref ( ) , database_id. as_deref ( ) ) . await ;
579570
580571 let resp = req
581572 . send ( )
@@ -605,30 +596,7 @@ impl Api {
605596 let session_id = self . session_id . clone ( ) ;
606597 rt ( ) . block_on ( async move {
607598 let mut req = cfg. client . request ( reqwest:: Method :: DELETE , & url) ;
608- if let Some ( ref user_agent) = cfg. user_agent {
609- req = req. header ( reqwest:: header:: USER_AGENT , user_agent. clone ( ) ) ;
610- }
611- if let Some ( apikey) = cfg. api_keys . get ( hotdata:: client:: WORKSPACE_ID_HEADER ) {
612- let value = match apikey. prefix {
613- Some ( ref prefix) => format ! ( "{} {}" , prefix, apikey. key) ,
614- None => apikey. key . clone ( ) ,
615- } ;
616- req = req. header ( hotdata:: client:: WORKSPACE_ID_HEADER , value) ;
617- }
618- // Sandbox session scope (also forwarded from api_keys on generated
619- // ops; set here for the raw seam paths).
620- if let Some ( ref sid) = session_id {
621- req = req. header ( "X-Session-Id" , sid. clone ( ) ) ;
622- }
623- // X-Database-Id scopes the request to a database. The old ApiClient
624- // attached it to every request when set; the SDK does not forward
625- // it, so the seam must (e.g. `hotdata query --database`).
626- if let Some ( ref db) = database_id {
627- req = req. header ( "X-Database-Id" , db. clone ( ) ) ;
628- }
629- if let Some ( token) = cfg. resolve_bearer_token ( ) . await {
630- req = req. bearer_auth ( token) ;
631- }
599+ req = apply_seam_headers ( req, cfg, session_id. as_deref ( ) , database_id. as_deref ( ) ) . await ;
632600
633601 let resp = req
634602 . send ( )
@@ -668,30 +636,7 @@ impl Api {
668636 . client
669637 . request ( reqwest:: Method :: GET , & url)
670638 . header ( reqwest:: header:: ACCEPT , accept) ;
671- if let Some ( ref user_agent) = cfg. user_agent {
672- req = req. header ( reqwest:: header:: USER_AGENT , user_agent. clone ( ) ) ;
673- }
674- if let Some ( apikey) = cfg. api_keys . get ( hotdata:: client:: WORKSPACE_ID_HEADER ) {
675- let value = match apikey. prefix {
676- Some ( ref prefix) => format ! ( "{} {}" , prefix, apikey. key) ,
677- None => apikey. key . clone ( ) ,
678- } ;
679- req = req. header ( hotdata:: client:: WORKSPACE_ID_HEADER , value) ;
680- }
681- // Sandbox session scope (also forwarded from api_keys on generated
682- // ops; set here for the raw seam paths).
683- if let Some ( ref sid) = session_id {
684- req = req. header ( "X-Session-Id" , sid. clone ( ) ) ;
685- }
686- // X-Database-Id scopes the request to a database. The old ApiClient
687- // attached it to every request when set; the SDK does not forward
688- // it, so the seam must (e.g. `hotdata query --database`).
689- if let Some ( ref db) = database_id {
690- req = req. header ( "X-Database-Id" , db. clone ( ) ) ;
691- }
692- if let Some ( token) = cfg. resolve_bearer_token ( ) . await {
693- req = req. bearer_auth ( token) ;
694- }
639+ req = apply_seam_headers ( req, cfg, session_id. as_deref ( ) , database_id. as_deref ( ) ) . await ;
695640
696641 let resp = req
697642 . send ( )
0 commit comments