MCPcopy Index your code
hub / github.com/github/copilot-sdk / start

Method start

test/harness/capturingHttpProxy.ts:21–130  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19 }
20
21 async start(): Promise<string> {
22 const targetUrlObj = new URL(this.targetUrl);
23 const isHttps = targetUrlObj.protocol === "https:";
24
25 this.server = http.createServer((req, res) => {
26 const chunks: Buffer[] = [];
27
28 req.on("data", (chunk: Buffer) => {
29 chunks.push(chunk);
30 });
31
32 req.on("end", () => {
33 const body = Buffer.concat(chunks).toString("utf8");
34 const startTime = Date.now();
35
36 const capturedRequest: CapturedRequest = {
37 method: req.method || "GET",
38 url: req.url || "/",
39 headers: req.headers,
40 body,
41 startTime,
42 };
43
44 const exchange: CapturedExchange = {
45 request: capturedRequest,
46 };
47
48 this.capturedExchanges.push(exchange);
49
50 // Copy headers but update Host to match target
51 const proxyHeaders = { ...req.headers };
52 proxyHeaders.host = targetUrlObj.host;
53 delete proxyHeaders.connection;
54
55 let responseStatusCode: number | undefined;
56 let responseHeaders: http.IncomingHttpHeaders | undefined;
57 const responseChunks: Buffer[] = [];
58 this.performRequest({
59 isHttps,
60 requestOptions: {
61 hostname: targetUrlObj.hostname,
62 port: targetUrlObj.port || (isHttps ? 443 : 80),
63 path: req.url,
64 method: req.method,
65 headers: proxyHeaders,
66 },
67 body,
68 onResponseStart: (statusCode, headers) => {
69 responseStatusCode = statusCode;
70 responseHeaders = headers;
71 res.writeHead(statusCode, responseHeaders);
72 },
73 onData: (chunk) => {
74 responseChunks.push(chunk);
75 res.write(chunk);
76 },
77 onResponseEnd: () => {
78 const endTime = Date.now();

Callers

nothing calls this directly

Calls 8

performRequestMethod · 0.95
StringFunction · 0.85
toStringMethod · 0.80
onMethod · 0.45
pushMethod · 0.45
writeMethod · 0.45
endMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected