Skip to content

Commit

Permalink
Omit adding the osd-version header when the Fetch request was expli…
Browse files Browse the repository at this point in the history
…citly asked to not prepend the `basePath`

Fixes #3277

Signed-off-by: Miki <miki@amazon.com>
  • Loading branch information
AMoo-Miki committed Mar 22, 2023
1 parent de06344 commit fb9468f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/public/http/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import { omitBy } from 'lodash';
import { format } from 'url';
import { BehaviorSubject } from 'rxjs';
import { isRelativeUrl } from '@osd/std';

import {
IBasePath,
Expand Down Expand Up @@ -144,7 +145,6 @@ export class Fetch {
headers: removedUndefined({
'Content-Type': 'application/json',
...options.headers,
'osd-version': this.params.opensearchDashboardsVersion,
}),
};

Expand All @@ -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);
}

Expand Down

0 comments on commit fb9468f

Please sign in to comment.