add: support custom headers
This commit is contained in:
@@ -54,6 +54,7 @@ interface UseConnectionOptions {
|
||||
env: Record<string, string>;
|
||||
bearerToken?: string;
|
||||
headerName?: string;
|
||||
customHeaders?: [string, string][];
|
||||
config: InspectorConfig;
|
||||
onNotification?: (notification: Notification) => void;
|
||||
onStdErrNotification?: (notification: Notification) => void;
|
||||
@@ -71,6 +72,7 @@ export function useConnection({
|
||||
env,
|
||||
bearerToken,
|
||||
headerName,
|
||||
customHeaders,
|
||||
config,
|
||||
onNotification,
|
||||
onStdErrNotification,
|
||||
@@ -287,7 +289,9 @@ export function useConnection({
|
||||
try {
|
||||
// Inject auth manually instead of using SSEClientTransport, because we're
|
||||
// proxying through the inspector server first.
|
||||
const headers: HeadersInit = {};
|
||||
const headers = new Headers(customHeaders||[]);
|
||||
|
||||
//const headers: HeadersInit = [ ...customHeaders||[] ];
|
||||
|
||||
// Create an auth provider with the current server URL
|
||||
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
|
||||
@@ -297,7 +301,7 @@ export function useConnection({
|
||||
bearerToken || (await serverAuthProvider.tokens())?.access_token;
|
||||
if (token) {
|
||||
const authHeaderName = headerName || "Authorization";
|
||||
headers[authHeaderName] = `Bearer ${token}`;
|
||||
headers.set(authHeaderName, `Bearer ${token}`);
|
||||
}
|
||||
|
||||
// Create appropriate transport
|
||||
|
||||
Reference in New Issue
Block a user