| 132 | } |
| 133 | |
| 134 | function buildRequestBody(payload: string, apiKey: string): PreparedBody { |
| 135 | const headers: Record<string, string> = { |
| 136 | 'Content-Type': 'application/json', |
| 137 | 'DD-API-KEY': apiKey, |
| 138 | Accept: 'application/json', |
| 139 | 'User-Agent': 'sim-data-drain/1.0', |
| 140 | } |
| 141 | const rawBytes = Buffer.byteLength(payload, 'utf8') |
| 142 | if (rawBytes > GZIP_THRESHOLD_BYTES) { |
| 143 | const compressed = gzipSync(payload) |
| 144 | headers['Content-Encoding'] = 'gzip' |
| 145 | const view = new Uint8Array(compressed.buffer, compressed.byteOffset, compressed.byteLength) |
| 146 | return { body: view, headers, wireBytes: view.byteLength, rawBytes } |
| 147 | } |
| 148 | return { body: payload, headers, wireBytes: rawBytes, rawBytes } |
| 149 | } |
| 150 | |
| 151 | async function postWithRetries(input: PostInput): Promise<Response> { |
| 152 | const { body, headers } = input.prepared |