@@ -238,11 +238,18 @@ export interface CreatePluginAtomClientOptions {
238238 /** Optional dynamic Authorization header for hosts whose active
239239 * Executor Server Connection requires Basic or Bearer auth. */
240240 readonly authorizationHeader ?: string | null | ( ( ) => string | null ) ;
241+ /** Optional dynamic request headers supplied by the host shell. */
242+ readonly headers ?:
243+ | Readonly < Record < string , string | null | undefined > >
244+ | ( ( ) => Readonly < Record < string , string | null | undefined > > ) ;
241245}
242246
243247export interface PluginAtomClientRequestTransformOptions {
244248 readonly baseUrl ?: ( ) => string ;
245249 readonly authorizationHeader ?: string | null | ( ( ) => string | null ) ;
250+ readonly headers ?:
251+ | Readonly < Record < string , string | null | undefined > >
252+ | ( ( ) => Readonly < Record < string , string | null | undefined > > ) ;
246253}
247254
248255/** @internal */
@@ -258,6 +265,14 @@ export const applyPluginAtomClientRequestTransform = (
258265 if ( authorization ) {
259266 next = HttpClientRequest . setHeader ( next , "authorization" , authorization ) ;
260267 }
268+ const headers = typeof options . headers === "function" ? options . headers ( ) : options . headers ;
269+ if ( headers ) {
270+ for ( const [ name , value ] of Object . entries ( headers ) ) {
271+ if ( value !== undefined && value !== null ) {
272+ next = HttpClientRequest . setHeader ( next , name , value ) ;
273+ }
274+ }
275+ }
261276 return next ;
262277} ;
263278
@@ -278,16 +293,17 @@ export const createPluginAtomClient = <
278293 group : G ,
279294 options : CreatePluginAtomClientOptions = { } ,
280295) => {
281- const { baseUrl = "/api" , authorizationHeader } = options ;
296+ const { baseUrl = "/api" , authorizationHeader, headers } = options ;
282297 const pluginId = group . identifier ;
283298 const bundle = HttpApi . make ( `plugin-${ pluginId } ` ) . add ( group ) ;
284299 const getBaseUrl = typeof baseUrl === "function" ? baseUrl : null ;
285300 const staticBaseUrl = typeof baseUrl === "function" ? undefined : baseUrl ;
286301 const getAuthorizationHeader =
287302 typeof authorizationHeader === "function" ? authorizationHeader : null ;
288303 const hasAuthorization = authorizationHeader !== undefined && authorizationHeader !== null ;
304+ const hasHeaders = headers !== undefined ;
289305 const transformClient =
290- getBaseUrl || hasAuthorization
306+ getBaseUrl || hasAuthorization || hasHeaders
291307 ? HttpClient . mapRequest ( ( request ) =>
292308 applyPluginAtomClientRequestTransform ( request , {
293309 ...( getBaseUrl ? { baseUrl : getBaseUrl } : { } ) ,
@@ -296,6 +312,7 @@ export const createPluginAtomClient = <
296312 : authorizationHeader !== undefined
297313 ? { authorizationHeader }
298314 : { } ) ,
315+ ...( headers !== undefined ? { headers } : { } ) ,
299316 } ) ,
300317 )
301318 : undefined ;
0 commit comments