Request change({Map<String, String> headers, Map<String, Object> context, String path, 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 or a Stream>.

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

Source

Request change({Map<String, String> headers, Map<String, Object> context,
    String path, body}) {
  headers = updateMap(this.headers, headers);
  context = updateMap(this.context, context);

  if (body == null) body = getBody(this);

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

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