Skip to content

Commit ffa9adb

Browse files
feat: support setting headers via env
1 parent fbbc840 commit ffa9adb

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/client.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@ export class Finch {
241241
this.fetch = options.fetch ?? Shims.getDefaultFetch();
242242
this.#encoder = Opts.FallbackEncoder;
243243

244+
const customHeadersEnv = readEnv('FINCH_CUSTOM_HEADERS');
245+
if (customHeadersEnv) {
246+
const parsed: Record<string, string> = {};
247+
for (const line of customHeadersEnv.split('\n')) {
248+
const colon = line.indexOf(':');
249+
if (colon >= 0) {
250+
parsed[line.substring(0, colon).trim()] = line.substring(colon + 1).trim();
251+
}
252+
}
253+
options.defaultHeaders = { ...parsed, ...options.defaultHeaders };
254+
}
255+
244256
this._options = options;
245257

246258
this.accessToken = accessToken;

0 commit comments

Comments
 (0)