MCPcopy Create free account
hub / github.com/callstack/agent-device / rewriteUploadDirectUrl

Function rewriteUploadDirectUrl

src/remote/daemon-proxy.ts:208–232  ·  view source on GitHub ↗
(upstreamUrl: string, req: IncomingMessage)

Source from the content-addressed store, hash-verified

206}
207
208function rewriteUploadDirectUrl(upstreamUrl: string, req: IncomingMessage): string | null {
209 let parsed: URL;
210 try {
211 parsed = new URL(upstreamUrl);
212 } catch {
213 return null;
214 }
215
216 if (!parsed.pathname.startsWith('/upload/')) {
217 return null;
218 }
219
220 const host = typeof req.headers.host === 'string' ? req.headers.host : '';
221 if (!host) return null;
222
223 const requestPath = new URL(req.url ?? '/', 'http://127.0.0.1').pathname;
224 const uploadIndex = requestPath.lastIndexOf('/upload/preflight');
225 const uploadPrefix = uploadIndex >= 0 ? requestPath.slice(0, uploadIndex) : '';
226 const forwardedProto = req.headers['x-forwarded-proto'];
227 const proto = Array.isArray(forwardedProto) ? forwardedProto[0] : forwardedProto;
228 const rewritten = new URL(`${proto || 'http'}://${host}`);
229 rewritten.pathname = `${uploadPrefix}${parsed.pathname}`;
230 rewritten.search = parsed.search;
231 return rewritten.toString();
232}
233
234async function pipeProxyResponseBody(response: Response, res: ServerResponse): Promise<void> {
235 if (!response.body) {

Callers 1

Calls 1

startsWithMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…