From b99c53b4e4bf5f346da9ed89f1b7b8f25c1d8d62 Mon Sep 17 00:00:00 2001 From: Chris Breederveld <40824795+Breederveld@users.noreply.github.com> Date: Sat, 30 Nov 2024 04:59:11 +0100 Subject: [PATCH] Allow additional headers (#669) Allow the client code to provide additional headers for custom implementations. Specifically the goal for us is to be able to include authentication using a bearer token, but this solution should cover other custom cases as well. Co-authored-by: Chris Breederveld --- src/MiniProfiler.Shared/ui/lib/MiniProfiler.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) mode change 100644 => 100755 src/MiniProfiler.Shared/ui/lib/MiniProfiler.ts diff --git a/src/MiniProfiler.Shared/ui/lib/MiniProfiler.ts b/src/MiniProfiler.Shared/ui/lib/MiniProfiler.ts old mode 100644 new mode 100755 index 2c78c0ef..fb97d051 --- a/src/MiniProfiler.Shared/ui/lib/MiniProfiler.ts +++ b/src/MiniProfiler.Shared/ui/lib/MiniProfiler.ts @@ -122,6 +122,7 @@ namespace StackExchange.Profiling { toggleShortcut: string; trivialMilliseconds: number; version: string; + additionalHeaders: object; } enum RenderMode { @@ -302,6 +303,7 @@ namespace StackExchange.Profiling { startHidden: bool(data.startHidden), ignoredDuplicateExecuteTypes: (data.ignoredDuplicateExecuteTypes || '').split(','), nonce: script.nonce, + additionalHeaders: {}, }; function doInit() { @@ -465,8 +467,9 @@ namespace StackExchange.Profiling { method: 'POST', body: JSON.stringify(request), headers: { + ...(this.options.additionalHeaders ?? {}), 'Accept': 'application/json', - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', } }) .then(data => data.text())