MCPcopy Create free account
hub / github.com/Martian-Engineering/pr-sheriff / splitHttpResponse

Function splitHttpResponse

src/github/github_fetch.mjs:24–47  ·  view source on GitHub ↗
(raw)

Source from the content-addressed store, hash-verified

22}
23
24function 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
49function parseLinkHeader(linkHeader) {
50 /** @type {Record<string, string>} */

Callers 2

#restRequestRawMethod · 0.85
#graphqlPaginateNodesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected