mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 08:48:39 +09:00
DevTools - network - Copy as cURL (POST)
https://github.com/MoonchildProductions/moebius/pull/167
This commit is contained in:
parent
1a8810305a
commit
59559355e6
2 changed files with 20 additions and 2 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue