feat: add metadata headers to response
This commit is contained in:
parent
61a49ceb32
commit
4d2eeb52b3
|
@ -17,4 +17,7 @@ export default {
|
|||
maxWebhookRetries: parseInt(get("MAX_RETRIES", "3")),
|
||||
maxWebhookRetryMs: parseInt(get("MAX_RETRY_MS", "30000")),
|
||||
mainRedirect: get("MAIN_REDIRECT", null),
|
||||
|
||||
// set by deno deploy
|
||||
deployId: get("DENO_DEPLOYMENT_ID", "<unknown>"),
|
||||
};
|
||||
|
|
|
@ -47,5 +47,23 @@ export async function sendWebhook(
|
|||
log.warning(`retrying after ${resetms}ms (retry ${retries})`);
|
||||
await sleep(resetms);
|
||||
} while (true);
|
||||
|
||||
// clone response to make headers mutable
|
||||
res = new Response(res.body, res);
|
||||
|
||||
// set metadata headers
|
||||
const meta: Record<string, string> = {
|
||||
"deploy": config.deployId,
|
||||
};
|
||||
if (retries) meta["retries"] = retries.toString();
|
||||
|
||||
setMetadata(res, meta);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
function setMetadata(res: Response, meta: Record<string, string>): void {
|
||||
for (const [key, value] of Object.entries(meta)) {
|
||||
res.headers.set(`x-webhook-filter-${key}`, value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue