change method

  1. @override
Response change({
  1. Map<String, Object?>? headers,
  2. Map<String, Object?>? context,
  3. Object? body,
})

Creates a new Response by copying existing values and applying specified changes.

New key-value pairs in context and headers will be added to the copied Response.

If context or headers includes a key that already exists, the key-value pair will replace the corresponding entry in the copied Response. If context or headers contains a null value the corresponding key will be removed if it exists, otherwise the null value will be ignored. For headers a value which is an empty list will also cause the corresponding key to be removed.

All other context and header values from the Response will be included in the copied Response unchanged.

body is the response body. It may be either a String, a List<int>, a Stream<List<int>>, or <int>[] (empty list) to indicate no body.

Implementation

@override
Response change({
  Map<String, /* String | List<String> */ Object?>? headers,
  Map<String, Object?>? context,
  Object? body,
}) {
  final headersAll = updateHeaders(this.headersAll, headers);
  final newContext = updateMap(this.context, context);

  body ??= extractBody(this);

  return Response(
    statusCode,
    body: body,
    headers: headersAll,
    context: newContext,
  );
}