@@ -243,11 +243,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
243
243
headers : {
244
244
...config . headers ,
245
245
'content-type' : 'application/json' ,
246
+ ...getAuthHeaders ( config , bearerToken ) ,
246
247
} ,
247
248
body : JSON . stringify ( payload ) ,
248
249
agent : config . agent ,
249
250
} ;
250
- addAuthHeaderIfNeeded ( request , bearerToken ) ;
251
251
return fetchWithTimeout ( url ( path ) , config . timeout ?. insert || 90 , request ) . then (
252
252
checkStatus < T > ( expectReturnContent )
253
253
) ;
@@ -263,11 +263,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
263
263
headers : {
264
264
...config . headers ,
265
265
'content-type' : 'application/json' ,
266
+ ...getAuthHeaders ( config , bearerToken ) ,
266
267
} ,
267
268
body : JSON . stringify ( payload ) ,
268
269
agent : config . agent ,
269
270
} ;
270
- addAuthHeaderIfNeeded ( request , bearerToken ) ;
271
271
return fetchWithTimeout ( url ( path ) , config . timeout ?. insert || 90 , request ) . then (
272
272
checkStatus < T > ( expectReturnContent )
273
273
) ;
@@ -278,11 +278,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
278
278
headers : {
279
279
...config . headers ,
280
280
'content-type' : 'application/json' ,
281
+ ...getAuthHeaders ( config , bearerToken ) ,
281
282
} ,
282
283
body : JSON . stringify ( payload ) ,
283
284
agent : config . agent ,
284
285
} ;
285
- addAuthHeaderIfNeeded ( request , bearerToken ) ;
286
286
return fetchWithTimeout ( url ( path ) , config . timeout ?. insert || 90 , request ) . then ( checkStatus < T > ( false ) ) ;
287
287
} ,
288
288
delete : < B > ( path : string , payload : B | null = null , expectReturnContent = false , bearerToken = '' ) => {
@@ -291,11 +291,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
291
291
headers : {
292
292
...config . headers ,
293
293
'content-type' : 'application/json' ,
294
+ ...getAuthHeaders ( config , bearerToken ) ,
294
295
} ,
295
296
body : payload ? JSON . stringify ( payload ) : undefined ,
296
297
agent : config . agent ,
297
298
} ;
298
- addAuthHeaderIfNeeded ( request , bearerToken ) ;
299
299
return fetchWithTimeout ( url ( path ) , config . timeout ?. insert || 90 , request ) . then (
300
300
checkStatus < undefined > ( expectReturnContent )
301
301
) ;
@@ -306,11 +306,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
306
306
headers : {
307
307
...config . headers ,
308
308
'content-type' : 'application/json' ,
309
+ ...getAuthHeaders ( config , bearerToken ) ,
309
310
} ,
310
311
body : payload ? JSON . stringify ( payload ) : undefined ,
311
312
agent : config . agent ,
312
313
} ;
313
- addAuthHeaderIfNeeded ( request , bearerToken ) ;
314
314
return fetchWithTimeout ( url ( path ) , config . timeout ?. query || 30 , request ) . then (
315
315
handleHeadResponse < undefined > ( false )
316
316
) ;
@@ -320,10 +320,10 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
320
320
method : 'GET' ,
321
321
headers : {
322
322
...config . headers ,
323
+ ...getAuthHeaders ( config , bearerToken ) ,
323
324
} ,
324
325
agent : config . agent ,
325
326
} ;
326
- addAuthHeaderIfNeeded ( request , bearerToken ) ;
327
327
return fetchWithTimeout ( url ( path ) , config . timeout ?. query || 30 , request ) . then (
328
328
checkStatus < any > ( expectReturnContent )
329
329
) ;
@@ -334,10 +334,10 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
334
334
method : 'GET' ,
335
335
headers : {
336
336
...config . headers ,
337
+ ...getAuthHeaders ( config , bearerToken ) ,
337
338
} ,
338
339
agent : config . agent ,
339
340
} ;
340
- addAuthHeaderIfNeeded ( request , bearerToken ) ;
341
341
return fetchWithTimeout ( url ( path ) , config . timeout ?. query || 30 , request ) ;
342
342
} ,
343
343
externalGet : ( externalUrl : string ) => {
@@ -406,8 +406,12 @@ const handleHeadResponse =
406
406
return checkStatus < T > ( expectResponseBody ) ( res ) ;
407
407
} ;
408
408
409
- function addAuthHeaderIfNeeded ( request : any , bearerToken : string ) {
410
- if ( bearerToken !== '' ) {
411
- request . headers . Authorization = `Bearer ${ bearerToken } ` ;
412
- }
413
- }
409
+ const getAuthHeaders = ( config : InternalConnectionParams , bearerToken : string ) =>
410
+ bearerToken
411
+ ? {
412
+ Authorization : `Bearer ${ bearerToken } ` ,
413
+ 'X-Weaviate-Cluster-Url' : config . host ,
414
+ // keeping for backwards compatibility for older clusters for now. On newer clusters, Embedding Service reuses Authorization header.
415
+ 'X-Weaviate-Api-Key' : bearerToken ,
416
+ }
417
+ : undefined ;
0 commit comments