ServerResponse.redirect constructor

ServerResponse.redirect(
  1. String location, {
  2. int statusCode = 301,
  3. Map<String, String>? headers,
})

Creates a redirect response (301, 302, 307, 308).

Implementation

factory ServerResponse.redirect(
  String location, {
  int statusCode = 301,
  Map<String, String>? headers,
}) {
  return ServerResponse(
    statusCode: statusCode,
    headers: {
      'Location': location,
      'Content-Type': 'text/plain; charset=utf-8',
      if (headers != null) ...headers,
    },
    body: 'Redirecting to $location...',
  );
}