Skip to content

Commit 70285d6

Browse files
feat: support setting headers via env
1 parent 38bf722 commit 70285d6

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
@@ -191,6 +191,18 @@ export class OzAPI {
191191
this.fetch = options.fetch ?? Shims.getDefaultFetch();
192192
this.#encoder = Opts.FallbackEncoder;
193193

194+
const customHeadersEnv = readEnv('OZ_API_CUSTOM_HEADERS');
195+
if (customHeadersEnv) {
196+
const parsed: Record<string, string> = {};
197+
for (const line of customHeadersEnv.split('\n')) {
198+
const colon = line.indexOf(':');
199+
if (colon >= 0) {
200+
parsed[line.substring(0, colon).trim()] = line.substring(colon + 1).trim();
201+
}
202+
}
203+
options.defaultHeaders = { ...parsed, ...options.defaultHeaders };
204+
}
205+
194206
this._options = options;
195207

196208
this.apiKey = apiKey;

0 commit comments

Comments
 (0)