MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / proxyToSimDeck

Function proxyToSimDeck

packages/ci-proxy-worker/src/index.ts:213–247  ·  view source on GitHub ↗
(
  request: Request,
  session: SessionCookie,
)

Source from the content-addressed store, hash-verified

211}
212
213async function proxyToSimDeck(
214 request: Request,
215 session: SessionCookie,
216): Promise<Response> {
217 const requestUrl = new URL(request.url);
218 const upstream = new URL(session.upstream);
219 const target = new URL(requestUrl.pathname + requestUrl.search, upstream);
220 target.searchParams.set("simdeckToken", session.token);
221 if (session.device && !target.searchParams.has("device")) {
222 target.searchParams.set("device", session.device);
223 }
224
225 const headers = new Headers(request.headers);
226 headers.set("X-SimDeck-Token", session.token);
227 headers.set("Host", target.host);
228 headers.delete("Cookie");
229
230 const response = await fetch(target.toString(), {
231 body: request.body,
232 headers,
233 method: request.method,
234 redirect: "manual",
235 });
236
237 const responseHeaders = new Headers(response.headers);
238 responseHeaders.delete("set-cookie");
239 responseHeaders.set("Cache-Control", "no-store");
240 rewriteLocationHeader(responseHeaders, upstream, requestUrl.origin);
241
242 return new Response(response.body, {
243 status: response.status,
244 statusText: response.statusText,
245 headers: responseHeaders,
246 });
247}
248
249function rewriteLocationHeader(
250 headers: Headers,

Callers 1

handleRequestFunction · 0.85

Calls 5

fetchFunction · 0.85
rewriteLocationHeaderFunction · 0.85
setMethod · 0.80
toStringMethod · 0.80
deleteMethod · 0.65

Tested by

no test coverage detected