Bug 1031956 - "Copy as cURL" is building GET when it should be POST. r=gasolin
authorStefan Yohansson <sy.fen0@gmail.com>
Sat, 18 Mar 2017 11:39:37 -0300
changeset 349531 a49b8b413df8c5b597e703f7f113582e01d59198
parent 349530 7eebc7de24c7e957b6ee47783a89eaee0ac7ff5c
child 349532 d56fb9484300ffbcb770709f14697faa314b29e6
push id88447
push userryanvm@gmail.com
push dateFri, 24 Mar 2017 19:22:14 +0000
treeherdermozilla-inbound@a49b8b413df8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgasolin
bugs1031956
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1031956 - "Copy as cURL" is building GET when it should be POST. r=gasolin - Added POST to create post data conditional; - Added test to check "--data" on curl generated command.
devtools/client/netmonitor/test/browser_net_curl-utils.js
devtools/client/shared/curl.js
--- a/devtools/client/netmonitor/test/browser_net_curl-utils.js
+++ b/devtools/client/netmonitor/test/browser_net_curl-utils.js
@@ -2,17 +2,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 /**
  * Tests Curl Utils functionality.
  */
 
-const { CurlUtils } = require("devtools/client/shared/curl");
+const { Curl, CurlUtils } = require("devtools/client/shared/curl");
 
 add_task(function* () {
   let { tab, monitor } = yield initNetMonitor(CURL_UTILS_URL);
   info("Starting test... ");
 
   let { gStore, windowRequire } = monitor.panelWin;
   let Actions = windowRequire("devtools/client/netmonitor/actions/index");
   let { getSortedRequests } = windowRequire("devtools/client/netmonitor/selectors/index");
@@ -34,16 +34,17 @@ add_task(function* () {
   };
 
   let data = yield createCurlData(requests.get, getLongString);
   testFindHeader(data);
 
   data = yield createCurlData(requests.post, getLongString);
   testIsUrlEncodedRequest(data);
   testWritePostDataTextParams(data);
+  testDataArgumentOnGeneratedCommand(data);
 
   data = yield createCurlData(requests.multipart, getLongString);
   testIsMultipartRequest(data);
   testGetMultipartBoundary(data);
   testMultiPartHeaders(data);
   testRemoveBinaryDataFromMultipartText(data);
 
   data = yield createCurlData(requests.multipartForm, getLongString);
@@ -95,16 +96,22 @@ function testMultiPartHeaders(data) {
 }
 
 function testWritePostDataTextParams(data) {
   let params = CurlUtils.writePostDataTextParams(data.postDataText);
   is(params, "param1=value1&param2=value2&param3=value3",
     "Should return a serialized representation of the request parameters");
 }
 
+function testDataArgumentOnGeneratedCommand(data) {
+  let curlCommand = Curl.generateCommand(data);
+  ok(curlCommand.includes("--data"),
+    "Should return a curl command with --data");
+}
+
 function testGetMultipartBoundary(data) {
   let boundary = CurlUtils.getMultipartBoundary(data);
   ok(/-{3,}\w+/.test(boundary),
     "A boundary string should be found in a multipart request.");
 }
 
 function testRemoveBinaryDataFromMultipartText(data) {
   let generatedBoundary = CurlUtils.getMultipartBoundary(data);
--- a/devtools/client/shared/curl.js
+++ b/devtools/client/shared/curl.js
@@ -71,17 +71,18 @@ const Curl = {
     // Add URL.
     command.push(escapeString(data.url));
 
     let postDataText = null;
     let multipartRequest = utils.isMultipartRequest(data);
 
     // Create post data.
     let postData = [];
-    if (utils.isUrlEncodedRequest(data) || data.method == "PUT") {
+    if (utils.isUrlEncodedRequest(data) ||
+          ["PUT", "POST"].includes(data.method)) {
       postDataText = data.postDataText;
       postData.push("--data");
       postData.push(escapeString(utils.writePostDataTextParams(postDataText)));
       ignoredHeaders.add("Content-Length");
     } else if (multipartRequest) {
       postDataText = data.postDataText;
       postData.push("--data-binary");
       let boundary = utils.getMultipartBoundary(data);