getCurlCommand method

String getCurlCommand()

Implementation

String getCurlCommand() {
  var compressed = false;
  var curlCmd = "curl";
  curlCmd += " -X " + method;
  var headers = request!.headers;
  headers.forEach((key, value) {
    if ("Accept-Encoding" == key && "gzip" == value) {
      compressed = true;
    }
    curlCmd += " -H \'$key: $value\'";
  });

  String? requestBody = request?.body.toString();
  if (requestBody != null && requestBody != '') {
    // try to keep to a single line and use a subshell to preserve any line breaks
    curlCmd += " --data \$'" + requestBody.replaceAll("\n", "\\n") + "'";
  }
  curlCmd += ((compressed) ? " --compressed " : " ") +
      "\'${secure ? 'https://' : 'http://'}$server$endpoint\'";
  return curlCmd;
}