MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / serveUpstream

Function serveUpstream

e2e/selfhost/oauth-refresh-cross-session.test.ts:57–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55 * simultaneous refresh instead of hoping the scheduler interleaves them.
56 */
57const serveUpstream = () =>
58 Effect.acquireRelease(
59 Effect.callback<UpstreamHandle>((resume) => {
60 const bearers: string[] = [];
61 const held: ServerResponse[] = [];
62 const server = createServer((request, response) => {
63 if (request.method === "GET" && (request.url ?? "").startsWith("/issues")) {
64 bearers.push((request.headers.authorization ?? "").replace(/^Bearer\s+/i, ""));
65 if (held.length < SESSIONS) {
66 held.push(response);
67 if (held.length === SESSIONS) {
68 for (const rejected of held) {
69 rejected.writeHead(401, { "content-type": "application/json" });
70 rejected.end(JSON.stringify({ error: "invalid_token" }));
71 }
72 }
73 return;
74 }
75 response.writeHead(200, { "content-type": "application/json" });
76 response.end(JSON.stringify({ issues: [] }));
77 return;
78 }
79 response.writeHead(404, { "content-type": "application/json" });
80 response.end(JSON.stringify({ error: "not_found" }));
81 });
82 server.listen(0, "127.0.0.1", () => {
83 const address = server.address();
84 const port = typeof address === "object" && address ? address.port : 0;
85 resume(
86 Effect.succeed({
87 url: `http://127.0.0.1:${port}`,
88 bearers: () => [...bearers],
89 close: () => {
90 server.close();
91 server.closeAllConnections();
92 },
93 }),
94 );
95 });
96 }),
97 (server) => Effect.sync(server.close),
98 );
99
100const spec = (
101 baseUrl: string,

Calls 8

resumeFunction · 0.85
pushMethod · 0.80
endMethod · 0.80
listenMethod · 0.80
addressMethod · 0.80
replaceMethod · 0.65
closeMethod · 0.65
syncMethod · 0.65

Tested by

no test coverage detected