@@ -282,7 +282,12 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
282282 let _ = responder. send ( Ok ( ( ) ) ) ;
283283 let ( message, session_id) = self
284284 . client
285- . post_message ( config. uri . clone ( ) , initialize_request, None , None )
285+ . post_message (
286+ config. uri . clone ( ) ,
287+ initialize_request,
288+ None ,
289+ self . config . auth_header ,
290+ )
286291 . await
287292 . map_err ( WorkerQuitReason :: fatal_context ( "send initialize request" ) ) ?
288293 . expect_initialized :: < C :: Error > ( )
@@ -339,7 +344,7 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
339344 config. uri . clone ( ) ,
340345 initialized_notification. message ,
341346 session_id. clone ( ) ,
342- None ,
347+ config . auth_header . clone ( ) ,
343348 )
344349 . await
345350 . map_err ( WorkerQuitReason :: fatal_context (
@@ -426,7 +431,12 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
426431 let WorkerSendRequest { message, responder } = send_request;
427432 let response = self
428433 . client
429- . post_message ( config. uri . clone ( ) , message, session_id. clone ( ) , None )
434+ . post_message (
435+ config. uri . clone ( ) ,
436+ message,
437+ session_id. clone ( ) ,
438+ config. auth_header . clone ( ) ,
439+ )
430440 . await ;
431441 let send_result = match response {
432442 Err ( e) => Err ( e) ,
@@ -505,6 +515,8 @@ pub struct StreamableHttpClientTransportConfig {
505515 pub channel_buffer_capacity : usize ,
506516 /// if true, the transport will not require a session to be established
507517 pub allow_stateless : bool ,
518+ /// The value to send in the authorization header
519+ pub auth_header : Option < String > ,
508520}
509521
510522impl StreamableHttpClientTransportConfig {
@@ -514,6 +526,17 @@ impl StreamableHttpClientTransportConfig {
514526 ..Default :: default ( )
515527 }
516528 }
529+
530+ /// Set the authorization header to send with requests
531+ ///
532+ /// # Arguments
533+ ///
534+ /// * `value` - The value to set
535+ pub fn auth_header < T : Into < String > > ( mut self , value : T ) -> Self {
536+ // set our authorization header
537+ self . auth_header = Some ( value. into ( ) ) ;
538+ self
539+ }
517540}
518541
519542impl Default for StreamableHttpClientTransportConfig {
@@ -523,6 +546,7 @@ impl Default for StreamableHttpClientTransportConfig {
523546 retry_config : Arc :: new ( ExponentialBackoff :: default ( ) ) ,
524547 channel_buffer_capacity : 16 ,
525548 allow_stateless : true ,
549+ auth_header : None ,
526550 }
527551 }
528552}
0 commit comments