Skip to content

Commit 8c3a517

Browse files
feat: support setting headers via env
1 parent c217b4e commit 8c3a517

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
@@ -203,6 +203,18 @@ export class ScanDocuments {
203203
this.fetch = options.fetch ?? Shims.getDefaultFetch();
204204
this.#encoder = Opts.FallbackEncoder;
205205

206+
const customHeadersEnv = readEnv('SCAN_DOCUMENTS_CUSTOM_HEADERS');
207+
if (customHeadersEnv) {
208+
const parsed: Record<string, string> = {};
209+
for (const line of customHeadersEnv.split('\n')) {
210+
const colon = line.indexOf(':');
211+
if (colon >= 0) {
212+
parsed[line.substring(0, colon).trim()] = line.substring(colon + 1).trim();
213+
}
214+
}
215+
options.defaultHeaders = { ...parsed, ...options.defaultHeaders };
216+
}
217+
206218
this._options = options;
207219

208220
this.apiKey = apiKey;

0 commit comments

Comments
 (0)