change method

  1. @override
Request change (
  1. {Map<String, Object> headers,
  2. Map<String, Object> context,
  3. String path,
  4. dynamic body}

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

New key-value pairs in context and headers will be added to the copied Request. If context or headers includes a key that already exists, the key-value pair will replace the corresponding entry in the copied Request. All other context and header values from the Request will be included in the copied Request unchanged.

body is the request body. It may be either a String, a List<int>, a Stream<List<int>>, or null to indicate no body.

path is used to update both handlerPath and url. It's designed for routing middleware, and represents the path from the current handler to the next handler. It must be a prefix of url; handlerPath becomes handlerPath + "/" + path, and url becomes relative to that. For example:

print(request.handlerPath); // => /static/
print(request.url);        // => dir/file.html

request = request.change(path: "dir");
print(request.handlerPath); // => /static/dir/
print(request.url);        // => file.html


Request change(
    {Map<String, /* String | List<String> */ Object> headers,
    Map<String, Object> context,
    String path,
    body}) {
  final headersAll = updateMap(this.headersAll, expandToHeadersAll(headers));
  context = updateMap(this.context, context);

  body ??= extractBody(this);

  var handlerPath = this.handlerPath;
  if (path != null) handlerPath += path;

  return Request._(method, requestedUri,
      protocolVersion: protocolVersion,
      headers: headersAll,
      handlerPath: handlerPath,
      body: body,
      context: context,
      onHijack: _onHijack);