(raw)
| 22 | } |
| 23 | |
| 24 | function splitHttpResponse(raw) { |
| 25 | // `gh api --include` uses LF line endings on macOS, but handle CRLF too. |
| 26 | const idx = raw.indexOf('\r\n\r\n') >= 0 ? raw.indexOf('\r\n\r\n') : raw.indexOf('\n\n'); |
| 27 | if (idx < 0) { |
| 28 | return { status: null, headers: {}, bodyText: raw }; |
| 29 | } |
| 30 | const headerText = raw.slice(0, idx); |
| 31 | const bodyText = raw.slice(idx + (raw[idx] === '\r' ? 4 : 2)); |
| 32 | const headerLines = headerText.split(/\r?\n/); |
| 33 | const statusLine = headerLines[0] || ''; |
| 34 | |
| 35 | const statusMatch = /HTTP\/\S+\s+(\d+)/.exec(statusLine); |
| 36 | const status = statusMatch ? Number(statusMatch[1]) : null; |
| 37 | |
| 38 | /** @type {Record<string, string>} */ |
| 39 | const headers = {}; |
| 40 | for (const line of headerLines.slice(1)) { |
| 41 | const m = /^([^:]+):\s*(.*)$/.exec(line); |
| 42 | if (!m) continue; |
| 43 | headers[m[1].toLowerCase()] = m[2]; |
| 44 | } |
| 45 | |
| 46 | return { status, headers, bodyText }; |
| 47 | } |
| 48 | |
| 49 | function parseLinkHeader(linkHeader) { |
| 50 | /** @type {Record<string, string>} */ |
no outgoing calls
no test coverage detected