(req: IncomingMessage, rpcBody: string | undefined)
| 345 | } |
| 346 | |
| 347 | function resolveRequestToken(req: IncomingMessage, rpcBody: string | undefined): string { |
| 348 | const authHeader = typeof req.headers.authorization === 'string' ? req.headers.authorization : ''; |
| 349 | if (authHeader.toLowerCase().startsWith('bearer ')) { |
| 350 | return authHeader.slice('bearer '.length); |
| 351 | } |
| 352 | const tokenHeader = req.headers['x-agent-device-token']; |
| 353 | if (typeof tokenHeader === 'string') return tokenHeader; |
| 354 | if (rpcBody) { |
| 355 | const bodyToken = readJsonRpcToken(rpcBody); |
| 356 | if (bodyToken) return bodyToken; |
| 357 | } |
| 358 | return ''; |
| 359 | } |
| 360 | |
| 361 | function rewriteRpcToken(body: string, upstreamToken: string): string { |
| 362 | const parsed = JSON.parse(body) as { params?: Record<string, unknown> }; |
no test coverage detected