-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcustom-headers.ts
More file actions
30 lines (26 loc) · 934 Bytes
/
custom-headers.ts
File metadata and controls
30 lines (26 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { POSTHOG_FLAG_HEADER_PREFIX } from '../lib/constants';
/**
* Builds a list of custom headers for ANTHROPIC_CUSTOM_HEADERS.
*/
export function createCustomHeaders(): {
add(key: string, value: string): void;
/** Add a feature flag for PostHog ($feature/<flagKey>: variant). */
addFlag(flagKey: string, variant: string): void;
encode(): string;
} {
const entries: Array<{ key: string; value: string }> = [];
return {
add(key: string, value: string): void {
const name =
key.startsWith('x-') || key.startsWith('X-') ? key : `X-${key}`;
entries.push({ key: name, value });
},
addFlag(flagKey: string, variant: string): void {
const headerName = POSTHOG_FLAG_HEADER_PREFIX + flagKey.toUpperCase();
entries.push({ key: headerName, value: variant });
},
encode(): string {
return entries.map(({ key, value }) => `${key}: ${value}`).join('\n');
},
};
}