MCPcopy Create free account
hub / github.com/vercel/vercel / sendRedirect

Method sendRedirect

packages/cli/src/util/dev/server.ts:1416–1452  ·  view source on GitHub ↗
(
    req: http.IncomingMessage,
    res: http.ServerResponse,
    requestId: string,
    location: string,
    statusCode: number = 302,
    responseTransforms?: Transform[]
  )

Source from the content-addressed store, hash-verified

1414 }
1415
1416 async sendRedirect(
1417 req: http.IncomingMessage,
1418 res: http.ServerResponse,
1419 requestId: string,
1420 location: string,
1421 statusCode: number = 302,
1422 responseTransforms?: Transform[]
1423 ): Promise<void> {
1424 output.debug(`Redirect ${statusCode}: ${location}`);
1425
1426 res.statusCode = statusCode;
1427 // Apply any previously stored response-transform context to the redirect's
1428 // headers.
1429 const redirectHeaders: http.OutgoingHttpHeaders = { location };
1430 if (responseTransforms) {
1431 applyResponseTransforms(redirectHeaders, responseTransforms);
1432 }
1433 this.setResponseHeaders(res, requestId, redirectHeaders);
1434
1435 let body: string;
1436 const { accept = 'text/plain' } = req.headers;
1437 if (accept.includes('json')) {
1438 res.setHeader('content-type', 'application/json');
1439 const json = JSON.stringify({
1440 redirect: location,
1441 status: String(statusCode),
1442 });
1443 body = `${json}\n`;
1444 } else if (accept.includes('html')) {
1445 res.setHeader('content-type', 'text/html; charset=utf-8');
1446 body = redirectTemplate({ location, statusCode });
1447 } else {
1448 res.setHeader('content-type', 'text/plain; charset=utf-8');
1449 body = `Redirecting...\n`;
1450 }
1451 res.end(body);
1452 }
1453
1454 getRequestIp(req: http.IncomingMessage): string {
1455 // TODO: respect the `x-forwarded-for` headers

Callers 2

delegateToServiceMethod · 0.95
DevServerClass · 0.95

Calls 3

setResponseHeadersMethod · 0.95
applyResponseTransformsFunction · 0.90
debugMethod · 0.80

Tested by

no test coverage detected