@@ -277,7 +277,12 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
277277 let _ = responder. send ( Ok ( ( ) ) ) ;
278278 let ( message, session_id) = self
279279 . client
280- . post_message ( config. uri . clone ( ) , initialize_request, None , None )
280+ . post_message (
281+ config. uri . clone ( ) ,
282+ initialize_request,
283+ None ,
284+ self . config . auth_header ,
285+ )
281286 . await
282287 . map_err ( WorkerQuitReason :: fatal_context ( "send initialize request" ) ) ?
283288 . expect_initialized :: < C :: Error > ( )
@@ -334,7 +339,7 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
334339 config. uri . clone ( ) ,
335340 initialized_notification. message ,
336341 session_id. clone ( ) ,
337- None ,
342+ config . auth_header . clone ( ) ,
338343 )
339344 . await
340345 . map_err ( WorkerQuitReason :: fatal_context (
@@ -421,7 +426,12 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
421426 let WorkerSendRequest { message, responder } = send_request;
422427 let response = self
423428 . client
424- . post_message ( config. uri . clone ( ) , message, session_id. clone ( ) , None )
429+ . post_message (
430+ config. uri . clone ( ) ,
431+ message,
432+ session_id. clone ( ) ,
433+ config. auth_header . clone ( ) ,
434+ )
425435 . await ;
426436 let send_result = match response {
427437 Err ( e) => Err ( e) ,
@@ -661,6 +671,8 @@ pub struct StreamableHttpClientTransportConfig {
661671 pub channel_buffer_capacity : usize ,
662672 /// if true, the transport will not require a session to be established
663673 pub allow_stateless : bool ,
674+ /// The value to send in the authorization header
675+ pub auth_header : Option < String > ,
664676}
665677
666678impl StreamableHttpClientTransportConfig {
@@ -670,6 +682,17 @@ impl StreamableHttpClientTransportConfig {
670682 ..Default :: default ( )
671683 }
672684 }
685+
686+ /// Set the authorization header to send with requests
687+ ///
688+ /// # Arguments
689+ ///
690+ /// * `value` - The value to set
691+ pub fn auth_header < T : Into < String > > ( mut self , value : T ) -> Self {
692+ // set our authorization header
693+ self . auth_header = Some ( value. into ( ) ) ;
694+ self
695+ }
673696}
674697
675698impl Default for StreamableHttpClientTransportConfig {
@@ -679,6 +702,7 @@ impl Default for StreamableHttpClientTransportConfig {
679702 retry_config : Arc :: new ( ExponentialBackoff :: default ( ) ) ,
680703 channel_buffer_capacity : 16 ,
681704 allow_stateless : true ,
705+ auth_header : None ,
682706 }
683707 }
684708}
0 commit comments