curlRepresentation function

String curlRepresentation(
  1. RequestOptions options
)

Implementation

String curlRepresentation(RequestOptions options) {
  /// Generates a CURL command representation for the given request options.
  List<String> components = ["${grey}curl -i "];

  // Building the CURL command components.
  components.add("-X ${options.method.toUpperCase()} ");

  options.headers.forEach((k, v) {
    if (k != "Cookie") {
      components.add("-H \"$k: $v\" ");
    }
  });

  var data = json.encode(options.data);
  data = data.replaceAll('"', '\\"');
  components.add("-d \"$data\" ");

  components.add("\"${options.uri.toString()}\" ");

  return components.join('\\\n\t');
}