From fb9468ffb7ef9509c9bac93585ddc2871404c2eb Mon Sep 17 00:00:00 2001 From: Miki Date: Tue, 21 Mar 2023 11:20:27 -0700 Subject: [PATCH] Omit adding the `osd-version` header when the Fetch request was explicitly asked to not prepend the `basePath` Fixes #3277 Signed-off-by: Miki --- src/core/public/http/fetch.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/public/http/fetch.ts b/src/core/public/http/fetch.ts index cefaa353f7fa..3fde5c542d18 100644 --- a/src/core/public/http/fetch.ts +++ b/src/core/public/http/fetch.ts @@ -31,6 +31,7 @@ import { omitBy } from 'lodash'; import { format } from 'url'; import { BehaviorSubject } from 'rxjs'; +import { isRelativeUrl } from '@osd/std'; import { IBasePath, @@ -144,7 +145,6 @@ export class Fetch { headers: removedUndefined({ 'Content-Type': 'application/json', ...options.headers, - 'osd-version': this.params.opensearchDashboardsVersion, }), }; @@ -158,6 +158,16 @@ export class Fetch { fetchOptions.headers['osd-system-request'] = 'true'; } + /* `osd-version` is used on the server-side to make sure that an incoming request originated from a front-end + * of the same version; see core/server/http/lifecycle_handlers.ts + * + * If url equals `basePath, starts with `basePath` + '/', or is relative, add `osd-version` header. + */ + const basePath = this.params.basePath.get(); + if (isRelativeUrl(url) || url === basePath || url.startsWith(`${basePath}/`)) { + fetchOptions.headers['osd-version'] = this.params.opensearchDashboardsVersion; + } + return new Request(url, fetchOptions as RequestInit); }