@@ -243,11 +243,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
243243 headers : {
244244 ...config . headers ,
245245 'content-type' : 'application/json' ,
246+ ...getAuthHeaders ( config , bearerToken ) ,
246247 } ,
247248 body : JSON . stringify ( payload ) ,
248249 agent : config . agent ,
249250 } ;
250- addAuthHeaderIfNeeded ( request , bearerToken ) ;
251251 return fetchWithTimeout ( url ( path ) , config . timeout ?. insert || 90 , request ) . then (
252252 checkStatus < T > ( expectReturnContent )
253253 ) ;
@@ -263,11 +263,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
263263 headers : {
264264 ...config . headers ,
265265 'content-type' : 'application/json' ,
266+ ...getAuthHeaders ( config , bearerToken ) ,
266267 } ,
267268 body : JSON . stringify ( payload ) ,
268269 agent : config . agent ,
269270 } ;
270- addAuthHeaderIfNeeded ( request , bearerToken ) ;
271271 return fetchWithTimeout ( url ( path ) , config . timeout ?. insert || 90 , request ) . then (
272272 checkStatus < T > ( expectReturnContent )
273273 ) ;
@@ -278,11 +278,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
278278 headers : {
279279 ...config . headers ,
280280 'content-type' : 'application/json' ,
281+ ...getAuthHeaders ( config , bearerToken ) ,
281282 } ,
282283 body : JSON . stringify ( payload ) ,
283284 agent : config . agent ,
284285 } ;
285- addAuthHeaderIfNeeded ( request , bearerToken ) ;
286286 return fetchWithTimeout ( url ( path ) , config . timeout ?. insert || 90 , request ) . then ( checkStatus < T > ( false ) ) ;
287287 } ,
288288 delete : < B > ( path : string , payload : B | null = null , expectReturnContent = false , bearerToken = '' ) => {
@@ -291,11 +291,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
291291 headers : {
292292 ...config . headers ,
293293 'content-type' : 'application/json' ,
294+ ...getAuthHeaders ( config , bearerToken ) ,
294295 } ,
295296 body : payload ? JSON . stringify ( payload ) : undefined ,
296297 agent : config . agent ,
297298 } ;
298- addAuthHeaderIfNeeded ( request , bearerToken ) ;
299299 return fetchWithTimeout ( url ( path ) , config . timeout ?. insert || 90 , request ) . then (
300300 checkStatus < undefined > ( expectReturnContent )
301301 ) ;
@@ -306,11 +306,11 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
306306 headers : {
307307 ...config . headers ,
308308 'content-type' : 'application/json' ,
309+ ...getAuthHeaders ( config , bearerToken ) ,
309310 } ,
310311 body : payload ? JSON . stringify ( payload ) : undefined ,
311312 agent : config . agent ,
312313 } ;
313- addAuthHeaderIfNeeded ( request , bearerToken ) ;
314314 return fetchWithTimeout ( url ( path ) , config . timeout ?. query || 30 , request ) . then (
315315 handleHeadResponse < undefined > ( false )
316316 ) ;
@@ -320,10 +320,10 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
320320 method : 'GET' ,
321321 headers : {
322322 ...config . headers ,
323+ ...getAuthHeaders ( config , bearerToken ) ,
323324 } ,
324325 agent : config . agent ,
325326 } ;
326- addAuthHeaderIfNeeded ( request , bearerToken ) ;
327327 return fetchWithTimeout ( url ( path ) , config . timeout ?. query || 30 , request ) . then (
328328 checkStatus < any > ( expectReturnContent )
329329 ) ;
@@ -334,10 +334,10 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
334334 method : 'GET' ,
335335 headers : {
336336 ...config . headers ,
337+ ...getAuthHeaders ( config , bearerToken ) ,
337338 } ,
338339 agent : config . agent ,
339340 } ;
340- addAuthHeaderIfNeeded ( request , bearerToken ) ;
341341 return fetchWithTimeout ( url ( path ) , config . timeout ?. query || 30 , request ) ;
342342 } ,
343343 externalGet : ( externalUrl : string ) => {
@@ -406,8 +406,12 @@ const handleHeadResponse =
406406 return checkStatus < T > ( expectResponseBody ) ( res ) ;
407407 } ;
408408
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