summaryrefslogtreecommitdiffstats
path: root/devtools/client
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-01 13:35:53 +0100
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-01 13:35:53 +0100
commit60edea0203637f9b146e06ba9f3c1e2fc37851da (patch)
treecb16f4876b0a699c448552e406a100605204fe22 /devtools/client
parentb43b4f25a8f195da2d54da9ebc5e415fb3b2a133 (diff)
downloadUXP-60edea0203637f9b146e06ba9f3c1e2fc37851da.tar
UXP-60edea0203637f9b146e06ba9f3c1e2fc37851da.tar.gz
UXP-60edea0203637f9b146e06ba9f3c1e2fc37851da.tar.lz
UXP-60edea0203637f9b146e06ba9f3c1e2fc37851da.tar.xz
UXP-60edea0203637f9b146e06ba9f3c1e2fc37851da.zip
DevTools - network - Copy as cURL (POST)
https://github.com/MoonchildProductions/moebius/pull/167
Diffstat (limited to 'devtools/client')
-rw-r--r--devtools/client/netmonitor/test/browser_net_curl-utils.js16
-rw-r--r--devtools/client/shared/curl.js6
2 files changed, 20 insertions, 2 deletions
diff --git a/devtools/client/netmonitor/test/browser_net_curl-utils.js b/devtools/client/netmonitor/test/browser_net_curl-utils.js
index 7a5fc7926..0d35c6141 100644
--- a/devtools/client/netmonitor/test/browser_net_curl-utils.js
+++ b/devtools/client/netmonitor/test/browser_net_curl-utils.js
@@ -7,7 +7,7 @@
* 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);
@@ -37,6 +37,8 @@ add_task(function* () {
data = yield createCurlData(requests.post.attachment, gNetwork);
testIsUrlEncodedRequest(data);
testWritePostDataTextParams(data);
+ testWriteEmptyPostDataTextParams(data);
+ testDataArgumentOnGeneratedCommand(data);
data = yield createCurlData(requests.multipart.attachment, gNetwork);
testIsMultipartRequest(data);
@@ -85,6 +87,18 @@ function testWritePostDataTextParams(data) {
"Should return a serialized representation of the request parameters");
}
+function testWriteEmptyPostDataTextParams(data) {
+ let params = CurlUtils.writePostDataTextParams(null);
+ is(params, "",
+ "Should return a empty string when no parameters provided");
+}
+
+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),
diff --git a/devtools/client/shared/curl.js b/devtools/client/shared/curl.js
index 44465193f..45122be37 100644
--- a/devtools/client/shared/curl.js
+++ b/devtools/client/shared/curl.js
@@ -76,7 +76,8 @@ const Curl = {
// 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)));
@@ -207,6 +208,9 @@ const CurlUtils = {
* Post data parameters.
*/
writePostDataTextParams: function (postDataText) {
+ if (!postDataText) {
+ return "";
+ }
let lines = postDataText.split("\r\n");
return lines[lines.length - 1];
},