Skip to content

Commit 289b3f6

Browse files
committed
https-request: optionally log the corresponding curl calls
It is often exceedingly tedious to reproduce webhook delivery failures, even though we now have a convenient script that finds the webhook corresponding to a failed slash command. Let's introduce an option (guarded by an environment variable) to log the exact `curl` call to reproduce the call that might have failed. This is guarded by default essentially for one reason: It also includes the authorization token, unredacted, which would be unsafe by default. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 7e819c2 commit 289b3f6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

GitForWindowsHelper/https-request.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ const httpsRequest = async (context, hostname, method, requestPath, body, header
1818
path: requestPath,
1919
headers
2020
}
21+
if (process.env.LOG_HTTPS_REQUESTS === 'true') {
22+
const quote = s => !s.match(/[\][.?*\\^_"'`{}()<>@~&+:;$%"; // \t\r\n]/) ? s : `'${s.replace(/'/g, "'\\''")}'`
23+
const commandLine = [
24+
'curl',
25+
options.method === 'GET' ? '' : `-X ${options.method}`,
26+
...Object.entries(options.headers).map(([key, value]) => `-H ${quote(`${key}: ${value}`)}`),
27+
body ? `-d ${quote(body)}` : '',
28+
`https://${options.hostname}${options.path}`,
29+
].filter(e => e).join(' ')
30+
;(context.error || console.error)(commandLine)
31+
}
2132
return new Promise((resolve, reject) => {
2233
try {
2334
const https = require('https')

0 commit comments

Comments
 (0)