@scalar/snippetz 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/index.js +168 -169
- package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
- package/dist/httpsnippet-lite/helpers/escape.js +69 -44
- package/dist/httpsnippet-lite/helpers/headers.js +17 -14
- package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
- package/dist/httpsnippet-lite/helpers/shell.js +13 -13
- package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
- package/dist/httpsnippet-lite/helpers/url.js +4 -8
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
- package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
- package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
- package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
- package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
- package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
- package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
- package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
- package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
- package/dist/httpsnippet-lite/targets/target.js +1 -1
- package/dist/index.js +2 -9
- package/dist/libs/http.js +68 -56
- package/dist/libs/javascript.js +77 -60
- package/dist/libs/php.js +59 -49
- package/dist/libs/rust.js +60 -33
- package/dist/libs/shell.js +14 -5
- package/dist/plugins/c/libcurl/index.js +1 -5
- package/dist/plugins/c/libcurl/libcurl.js +13 -13
- package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
- package/dist/plugins/clojure/clj_http/index.js +1 -5
- package/dist/plugins/csharp/httpclient/httpclient.js +186 -150
- package/dist/plugins/csharp/httpclient/index.js +1 -5
- package/dist/plugins/csharp/restsharp/index.js +1 -5
- package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
- package/dist/plugins/dart/http/http.js +95 -93
- package/dist/plugins/dart/http/index.js +1 -5
- package/dist/plugins/fsharp/httpclient/httpclient.js +156 -122
- package/dist/plugins/fsharp/httpclient/index.js +1 -5
- package/dist/plugins/go/native/index.js +1 -5
- package/dist/plugins/go/native/native.js +13 -13
- package/dist/plugins/http/http11/http11.js +103 -85
- package/dist/plugins/http/http11/index.js +1 -5
- package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
- package/dist/plugins/java/asynchttp/index.js +1 -5
- package/dist/plugins/java/nethttp/index.js +1 -5
- package/dist/plugins/java/nethttp/nethttp.js +13 -13
- package/dist/plugins/java/okhttp/index.js +1 -5
- package/dist/plugins/java/okhttp/okhttp.js +13 -13
- package/dist/plugins/java/unirest/index.js +1 -5
- package/dist/plugins/java/unirest/unirest.js +13 -13
- package/dist/plugins/js/axios/axios.js +13 -13
- package/dist/plugins/js/axios/index.js +1 -5
- package/dist/plugins/js/fetch/fetch.js +82 -68
- package/dist/plugins/js/fetch/index.js +1 -5
- package/dist/plugins/js/jquery/index.js +1 -5
- package/dist/plugins/js/jquery/jquery.js +13 -13
- package/dist/plugins/js/ofetch/index.js +1 -5
- package/dist/plugins/js/ofetch/ofetch.js +61 -48
- package/dist/plugins/js/xhr/index.js +1 -5
- package/dist/plugins/js/xhr/xhr.js +13 -13
- package/dist/plugins/kotlin/okhttp/index.js +1 -5
- package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
- package/dist/plugins/node/axios/axios.js +13 -13
- package/dist/plugins/node/axios/index.js +1 -5
- package/dist/plugins/node/fetch/fetch.js +86 -74
- package/dist/plugins/node/fetch/index.js +1 -5
- package/dist/plugins/node/ofetch/index.js +1 -5
- package/dist/plugins/node/ofetch/ofetch.js +61 -48
- package/dist/plugins/node/undici/index.js +1 -5
- package/dist/plugins/node/undici/undici.js +60 -47
- package/dist/plugins/objc/nsurlsession/index.js +1 -5
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
- package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
- package/dist/plugins/ocaml/cohttp/index.js +1 -5
- package/dist/plugins/php/curl/curl.js +143 -101
- package/dist/plugins/php/curl/index.js +1 -5
- package/dist/plugins/php/guzzle/guzzle.js +103 -83
- package/dist/plugins/php/guzzle/index.js +1 -5
- package/dist/plugins/powershell/restmethod/index.js +1 -5
- package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
- package/dist/plugins/powershell/webrequest/index.js +1 -5
- package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
- package/dist/plugins/python/httpx/async.js +17 -15
- package/dist/plugins/python/httpx/index.js +2 -7
- package/dist/plugins/python/httpx/sync.js +11 -12
- package/dist/plugins/python/python3/index.js +1 -5
- package/dist/plugins/python/python3/python3.js +13 -13
- package/dist/plugins/python/requests/index.js +1 -5
- package/dist/plugins/python/requests/requests.js +11 -12
- package/dist/plugins/python/requestsLike.js +128 -112
- package/dist/plugins/r/httr/httr.js +13 -13
- package/dist/plugins/r/httr/index.js +1 -5
- package/dist/plugins/ruby/native/index.js +1 -5
- package/dist/plugins/ruby/native/native.js +13 -13
- package/dist/plugins/rust/reqwest/index.js +1 -5
- package/dist/plugins/rust/reqwest/reqwest.js +110 -83
- package/dist/plugins/shell/curl/curl.js +128 -97
- package/dist/plugins/shell/curl/index.js +1 -5
- package/dist/plugins/shell/httpie/httpie.js +13 -13
- package/dist/plugins/shell/httpie/index.js +1 -5
- package/dist/plugins/shell/wget/index.js +1 -5
- package/dist/plugins/shell/wget/wget.js +13 -13
- package/dist/plugins/swift/nsurlsession/index.js +1 -5
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
- package/dist/snippetz.js +25 -28
- package/dist/utils/convertWithHttpSnippetLite.js +100 -96
- package/dist/utils/index.js +1 -5
- package/package.json +8 -12
- package/dist/clients/index.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/target.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/libs/http.js.map +0 -7
- package/dist/libs/javascript.js.map +0 -7
- package/dist/libs/php.js.map +0 -7
- package/dist/libs/rust.js.map +0 -7
- package/dist/libs/shell.js.map +0 -7
- package/dist/plugins/c/libcurl/index.js.map +0 -7
- package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
- package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
- package/dist/plugins/clojure/clj_http/index.js.map +0 -7
- package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/csharp/httpclient/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
- package/dist/plugins/dart/http/http.js.map +0 -7
- package/dist/plugins/dart/http/index.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
- package/dist/plugins/go/native/index.js.map +0 -7
- package/dist/plugins/go/native/native.js.map +0 -7
- package/dist/plugins/http/http11/http11.js.map +0 -7
- package/dist/plugins/http/http11/index.js.map +0 -7
- package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
- package/dist/plugins/java/asynchttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
- package/dist/plugins/java/okhttp/index.js.map +0 -7
- package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/java/unirest/index.js.map +0 -7
- package/dist/plugins/java/unirest/unirest.js.map +0 -7
- package/dist/plugins/js/axios/axios.js.map +0 -7
- package/dist/plugins/js/axios/index.js.map +0 -7
- package/dist/plugins/js/fetch/fetch.js.map +0 -7
- package/dist/plugins/js/fetch/index.js.map +0 -7
- package/dist/plugins/js/jquery/index.js.map +0 -7
- package/dist/plugins/js/jquery/jquery.js.map +0 -7
- package/dist/plugins/js/ofetch/index.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/js/xhr/index.js.map +0 -7
- package/dist/plugins/js/xhr/xhr.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/node/axios/axios.js.map +0 -7
- package/dist/plugins/node/axios/index.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.js.map +0 -7
- package/dist/plugins/node/fetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/node/undici/index.js.map +0 -7
- package/dist/plugins/node/undici/undici.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
- package/dist/plugins/php/curl/curl.js.map +0 -7
- package/dist/plugins/php/curl/index.js.map +0 -7
- package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
- package/dist/plugins/php/guzzle/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
- package/dist/plugins/powershell/webrequest/index.js.map +0 -7
- package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
- package/dist/plugins/python/httpx/async.js.map +0 -7
- package/dist/plugins/python/httpx/index.js.map +0 -7
- package/dist/plugins/python/httpx/sync.js.map +0 -7
- package/dist/plugins/python/python3/index.js.map +0 -7
- package/dist/plugins/python/python3/python3.js.map +0 -7
- package/dist/plugins/python/requests/index.js.map +0 -7
- package/dist/plugins/python/requests/requests.js.map +0 -7
- package/dist/plugins/python/requestsLike.js.map +0 -7
- package/dist/plugins/r/httr/httr.js.map +0 -7
- package/dist/plugins/r/httr/index.js.map +0 -7
- package/dist/plugins/ruby/native/index.js.map +0 -7
- package/dist/plugins/ruby/native/native.js.map +0 -7
- package/dist/plugins/rust/reqwest/index.js.map +0 -7
- package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
- package/dist/plugins/shell/curl/curl.js.map +0 -7
- package/dist/plugins/shell/curl/index.js.map +0 -7
- package/dist/plugins/shell/httpie/httpie.js.map +0 -7
- package/dist/plugins/shell/httpie/index.js.map +0 -7
- package/dist/plugins/shell/wget/index.js.map +0 -7
- package/dist/plugins/shell/wget/wget.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/snippetz.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
- package/dist/utils/index.js.map +0 -7
|
@@ -1,104 +1,146 @@
|
|
|
1
|
-
import { objectToString } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
if (allHeaders.length) {
|
|
39
|
-
const headerStrings = allHeaders.map((header) => `'${header.name}: ${header.value}'`);
|
|
40
|
-
parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, [${headerStrings.join(", ")}]);`);
|
|
41
|
-
const acceptEncoding = allHeaders.find((header) => header.name.toLowerCase() === "accept-encoding");
|
|
42
|
-
if (acceptEncoding && /gzip|deflate/.test(acceptEncoding.value)) {
|
|
43
|
-
parts.push("curl_setopt($ch, CURLOPT_ENCODING, '');");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (normalizedRequest.cookies?.length) {
|
|
47
|
-
const cookieString = normalizedRequest.cookies.map((cookie) => {
|
|
48
|
-
const encodedName = encodeURIComponent(cookie.name);
|
|
49
|
-
const encodedValue = encodeURIComponent(cookie.value);
|
|
50
|
-
return `${encodedName}=${encodedValue}`;
|
|
51
|
-
}).join("; ");
|
|
52
|
-
parts.push(`curl_setopt($ch, CURLOPT_COOKIE, '${cookieString}');`);
|
|
53
|
-
}
|
|
54
|
-
if (normalizedRequest.postData) {
|
|
55
|
-
if (normalizedRequest.postData.mimeType === "application/json") {
|
|
56
|
-
if (normalizedRequest.postData.text) {
|
|
57
|
-
try {
|
|
58
|
-
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
59
|
-
const phpArray = objectToString(jsonData);
|
|
60
|
-
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(${phpArray}));`);
|
|
61
|
-
} catch {
|
|
62
|
-
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text}');`);
|
|
63
|
-
}
|
|
1
|
+
import { objectToString } from '../../../libs/php.js';
|
|
2
|
+
/**
|
|
3
|
+
* php/curl
|
|
4
|
+
*/
|
|
5
|
+
export const phpCurl = {
|
|
6
|
+
target: 'php',
|
|
7
|
+
client: 'curl',
|
|
8
|
+
title: 'cURL',
|
|
9
|
+
generate(request, configuration) {
|
|
10
|
+
// Defaults
|
|
11
|
+
const normalizedRequest = {
|
|
12
|
+
method: 'GET',
|
|
13
|
+
...request,
|
|
14
|
+
};
|
|
15
|
+
// Normalization
|
|
16
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
17
|
+
// Build PHP cURL code parts
|
|
18
|
+
const parts = [];
|
|
19
|
+
// Initialize cURL
|
|
20
|
+
// URL (with query parameters)
|
|
21
|
+
const queryString = normalizedRequest.queryString?.length
|
|
22
|
+
? '?' +
|
|
23
|
+
normalizedRequest.queryString
|
|
24
|
+
.map((param) => {
|
|
25
|
+
const encodedName = encodeURIComponent(param.name);
|
|
26
|
+
const encodedValue = encodeURIComponent(param.value);
|
|
27
|
+
return `${encodedName}=${encodedValue}`;
|
|
28
|
+
})
|
|
29
|
+
.join('&')
|
|
30
|
+
: '';
|
|
31
|
+
const url = `${normalizedRequest.url}${queryString}`;
|
|
32
|
+
parts.push(`$ch = curl_init("${url}");`);
|
|
33
|
+
parts.push('');
|
|
34
|
+
// Method
|
|
35
|
+
if (normalizedRequest.method === 'POST') {
|
|
36
|
+
parts.push('curl_setopt($ch, CURLOPT_POST, true);');
|
|
64
37
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
acc.push(`'${param.name}' => '@${param.fileName}'`);
|
|
69
|
-
} else if (param.value !== void 0) {
|
|
70
|
-
acc.push(`'${param.name}' => '${param.value}'`);
|
|
71
|
-
}
|
|
72
|
-
return acc;
|
|
73
|
-
}, []);
|
|
74
|
-
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, [${formData.join(", ")}]);`);
|
|
75
|
-
} else if (normalizedRequest.postData.mimeType === "application/x-www-form-urlencoded" && normalizedRequest.postData.params) {
|
|
76
|
-
const formData = normalizedRequest.postData.params.map((param) => {
|
|
77
|
-
const encodedName = encodeURIComponent(param.name);
|
|
78
|
-
const encodedValue = param.value ? encodeURIComponent(param.value) : "";
|
|
79
|
-
return `${encodedName}=${encodedValue}`;
|
|
80
|
-
}).join("&");
|
|
81
|
-
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${formData}');`);
|
|
82
|
-
} else if (normalizedRequest.postData.mimeType === "application/octet-stream") {
|
|
83
|
-
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text || ""}');`);
|
|
84
|
-
} else if (normalizedRequest.postData.text) {
|
|
85
|
-
try {
|
|
86
|
-
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
87
|
-
const phpArray = objectToString(jsonData);
|
|
88
|
-
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(${phpArray}));`);
|
|
89
|
-
} catch {
|
|
90
|
-
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text}');`);
|
|
38
|
+
// Basic Auth
|
|
39
|
+
if (configuration?.auth?.username && configuration?.auth?.password) {
|
|
40
|
+
parts.push(`curl_setopt($ch, CURLOPT_USERPWD, '${configuration.auth.username}:${configuration.auth.password}');`);
|
|
91
41
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
42
|
+
// Collect all headers to emit once, avoiding duplicate CURLOPT_HTTPHEADER calls.
|
|
43
|
+
// Body processing may add a Content-Type header, so we determine it first.
|
|
44
|
+
const allHeaders = [...(normalizedRequest.headers || [])];
|
|
45
|
+
// Helper to add Content-Type header if not already present
|
|
46
|
+
const hasContentType = () => allHeaders.some((h) => h.name.toLowerCase() === 'content-type');
|
|
47
|
+
// Determine Content-Type from body before emitting headers
|
|
48
|
+
if (normalizedRequest.postData) {
|
|
49
|
+
if (normalizedRequest.postData.mimeType === 'multipart/form-data' &&
|
|
50
|
+
normalizedRequest.postData.params &&
|
|
51
|
+
!hasContentType()) {
|
|
52
|
+
allHeaders.push({ name: 'Content-Type', value: 'multipart/form-data' });
|
|
53
|
+
}
|
|
54
|
+
else if (normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded' &&
|
|
55
|
+
normalizedRequest.postData.params &&
|
|
56
|
+
!hasContentType()) {
|
|
57
|
+
allHeaders.push({ name: 'Content-Type', value: 'application/x-www-form-urlencoded' });
|
|
58
|
+
}
|
|
59
|
+
else if (normalizedRequest.postData.mimeType === 'application/octet-stream' && !hasContentType()) {
|
|
60
|
+
allHeaders.push({ name: 'Content-Type', value: 'application/octet-stream' });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Emit all headers once
|
|
64
|
+
if (allHeaders.length) {
|
|
65
|
+
const headerStrings = allHeaders.map((header) => `'${header.name}: ${header.value}'`);
|
|
66
|
+
parts.push(`curl_setopt($ch, CURLOPT_HTTPHEADER, [${headerStrings.join(', ')}]);`);
|
|
67
|
+
// Add encoding option if Accept-Encoding header includes compression
|
|
68
|
+
const acceptEncoding = allHeaders.find((header) => header.name.toLowerCase() === 'accept-encoding');
|
|
69
|
+
if (acceptEncoding && /gzip|deflate/.test(acceptEncoding.value)) {
|
|
70
|
+
parts.push("curl_setopt($ch, CURLOPT_ENCODING, '');");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Cookies
|
|
74
|
+
if (normalizedRequest.cookies?.length) {
|
|
75
|
+
const cookieString = normalizedRequest.cookies
|
|
76
|
+
.map((cookie) => {
|
|
77
|
+
const encodedName = encodeURIComponent(cookie.name);
|
|
78
|
+
const encodedValue = encodeURIComponent(cookie.value);
|
|
79
|
+
return `${encodedName}=${encodedValue}`;
|
|
80
|
+
})
|
|
81
|
+
.join('; ');
|
|
82
|
+
parts.push(`curl_setopt($ch, CURLOPT_COOKIE, '${cookieString}');`);
|
|
83
|
+
}
|
|
84
|
+
// Body
|
|
85
|
+
if (normalizedRequest.postData) {
|
|
86
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
87
|
+
// Convert JSON to PHP array syntax
|
|
88
|
+
if (normalizedRequest.postData.text) {
|
|
89
|
+
try {
|
|
90
|
+
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
91
|
+
const phpArray = objectToString(jsonData);
|
|
92
|
+
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(${phpArray}));`);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text}');`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (normalizedRequest.postData.mimeType === 'multipart/form-data' && normalizedRequest.postData.params) {
|
|
100
|
+
// Handle multipart form data
|
|
101
|
+
const formData = normalizedRequest.postData.params.reduce((acc, param) => {
|
|
102
|
+
if (param.fileName !== undefined) {
|
|
103
|
+
acc.push(`'${param.name}' => '@${param.fileName}'`);
|
|
104
|
+
}
|
|
105
|
+
else if (param.value !== undefined) {
|
|
106
|
+
acc.push(`'${param.name}' => '${param.value}'`);
|
|
107
|
+
}
|
|
108
|
+
return acc;
|
|
109
|
+
}, []);
|
|
110
|
+
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, [${formData.join(', ')}]);`);
|
|
111
|
+
}
|
|
112
|
+
else if (normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded' &&
|
|
113
|
+
normalizedRequest.postData.params) {
|
|
114
|
+
// Handle URL-encoded form data
|
|
115
|
+
const formData = normalizedRequest.postData.params
|
|
116
|
+
.map((param) => {
|
|
117
|
+
const encodedName = encodeURIComponent(param.name);
|
|
118
|
+
const encodedValue = param.value ? encodeURIComponent(param.value) : '';
|
|
119
|
+
return `${encodedName}=${encodedValue}`;
|
|
120
|
+
})
|
|
121
|
+
.join('&');
|
|
122
|
+
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${formData}');`);
|
|
123
|
+
}
|
|
124
|
+
else if (normalizedRequest.postData.mimeType === 'application/octet-stream') {
|
|
125
|
+
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text || ''}');`);
|
|
126
|
+
}
|
|
127
|
+
else if (normalizedRequest.postData.text) {
|
|
128
|
+
// Try to parse as JSON and convert to PHP array, otherwise use raw text
|
|
129
|
+
try {
|
|
130
|
+
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
131
|
+
const phpArray = objectToString(jsonData);
|
|
132
|
+
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(${phpArray}));`);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
parts.push(`curl_setopt($ch, CURLOPT_POSTFIELDS, '${normalizedRequest.postData.text}');`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Execute and close
|
|
140
|
+
parts.push('');
|
|
141
|
+
parts.push('curl_exec($ch);');
|
|
142
|
+
parts.push('');
|
|
143
|
+
parts.push('curl_close($ch);');
|
|
144
|
+
return parts.join('\n').replace(/\n\n\n/g, '\n\n');
|
|
145
|
+
},
|
|
103
146
|
};
|
|
104
|
-
//# sourceMappingURL=curl.js.map
|
|
@@ -1,88 +1,108 @@
|
|
|
1
|
-
import { reduceQueryParams } from
|
|
2
|
-
import { Raw, objectToString } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const url = request.url || "";
|
|
14
|
-
if (request.headers && Array.isArray(request.headers) && request.headers.length > 0) {
|
|
15
|
-
const headers = {};
|
|
16
|
-
request.headers.forEach((header) => {
|
|
17
|
-
if (headers[header.name] === void 0) {
|
|
18
|
-
headers[header.name] = header.value;
|
|
19
|
-
} else if (Array.isArray(headers[header.name])) {
|
|
20
|
-
headers[header.name].push(header.value);
|
|
21
|
-
} else {
|
|
22
|
-
headers[header.name] = [headers[header.name], header.value];
|
|
1
|
+
import { reduceQueryParams } from '../../../libs/http.js';
|
|
2
|
+
import { Raw, objectToString } from '../../../libs/php.js';
|
|
3
|
+
/**
|
|
4
|
+
* php/guzzle
|
|
5
|
+
*/
|
|
6
|
+
export const phpGuzzle = {
|
|
7
|
+
target: 'php',
|
|
8
|
+
client: 'guzzle',
|
|
9
|
+
title: 'Guzzle',
|
|
10
|
+
generate(request, configuration) {
|
|
11
|
+
if (!request) {
|
|
12
|
+
return '';
|
|
23
13
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
options.json = JSON.parse(request.postData.text || "{}");
|
|
44
|
-
} catch (_e) {
|
|
45
|
-
options.body = request.postData.text;
|
|
14
|
+
const options = {};
|
|
15
|
+
const method = (request.method || 'GET').toUpperCase();
|
|
16
|
+
const url = request.url || '';
|
|
17
|
+
// Handle headers
|
|
18
|
+
if (request.headers && Array.isArray(request.headers) && request.headers.length > 0) {
|
|
19
|
+
const headers = {};
|
|
20
|
+
request.headers.forEach((header) => {
|
|
21
|
+
if (headers[header.name] === undefined) {
|
|
22
|
+
headers[header.name] = header.value;
|
|
23
|
+
}
|
|
24
|
+
else if (Array.isArray(headers[header.name])) {
|
|
25
|
+
headers[header.name].push(header.value);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
headers[header.name] = [headers[header.name], header.value];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
options.headers = headers;
|
|
46
32
|
}
|
|
47
|
-
|
|
48
|
-
if (request.
|
|
49
|
-
|
|
50
|
-
name: param.name,
|
|
51
|
-
contents: param.fileName ? new Raw(`fopen('${param.fileName}', 'r')`) : param.value || ""
|
|
52
|
-
}));
|
|
53
|
-
} else if (request.postData.text) {
|
|
54
|
-
try {
|
|
55
|
-
options.form_params = JSON.parse(request.postData.text);
|
|
56
|
-
} catch (_e) {
|
|
57
|
-
options.body = request.postData.text;
|
|
58
|
-
}
|
|
33
|
+
// Handle query parameters
|
|
34
|
+
if (request.queryString && request.queryString.length > 0) {
|
|
35
|
+
options.query = reduceQueryParams(request.queryString);
|
|
59
36
|
}
|
|
60
|
-
|
|
61
|
-
if (request.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
37
|
+
// Handle cookies
|
|
38
|
+
if (request.cookies && request.cookies.length > 0) {
|
|
39
|
+
const cookies = {};
|
|
40
|
+
request.cookies.forEach((cookie) => {
|
|
41
|
+
cookies[cookie.name] = cookie.value;
|
|
42
|
+
});
|
|
43
|
+
options.cookies = cookies;
|
|
67
44
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
45
|
+
// Handle authentication
|
|
46
|
+
if (configuration?.auth?.username && configuration.auth.password) {
|
|
47
|
+
options.auth = [configuration.auth.username, configuration.auth.password];
|
|
48
|
+
}
|
|
49
|
+
// Handle request body
|
|
50
|
+
if (request.postData) {
|
|
51
|
+
if (request.postData.mimeType === 'application/json') {
|
|
52
|
+
try {
|
|
53
|
+
options.json = JSON.parse(request.postData.text || '{}');
|
|
54
|
+
}
|
|
55
|
+
catch (_e) {
|
|
56
|
+
// If JSON parsing fails, use the raw text
|
|
57
|
+
options.body = request.postData.text;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (request.postData.mimeType === 'multipart/form-data') {
|
|
61
|
+
if (request.postData.params) {
|
|
62
|
+
options.multipart = request.postData.params.map((param) => ({
|
|
63
|
+
name: param.name,
|
|
64
|
+
contents: param.fileName ? new Raw(`fopen('${param.fileName}', 'r')`) : param.value || '',
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
else if (request.postData.text) {
|
|
68
|
+
try {
|
|
69
|
+
options.form_params = JSON.parse(request.postData.text);
|
|
70
|
+
}
|
|
71
|
+
catch (_e) {
|
|
72
|
+
options.body = request.postData.text;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (request.postData.mimeType === 'application/x-www-form-urlencoded') {
|
|
77
|
+
if (request.postData.params) {
|
|
78
|
+
const formParams = {};
|
|
79
|
+
request.postData.params.forEach((param) => {
|
|
80
|
+
formParams[param.name] = param.value || '';
|
|
81
|
+
});
|
|
82
|
+
options.form_params = formParams;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// For other mime types (like application/octet-stream), use the raw body
|
|
87
|
+
options.body = request.postData.text;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Handle compressed responses
|
|
91
|
+
if (request.headers &&
|
|
92
|
+
Array.isArray(request.headers) &&
|
|
93
|
+
request.headers.some((h) => h.name === 'Accept-Encoding' && h.value.includes('gzip'))) {
|
|
94
|
+
options.decode_content = true;
|
|
95
|
+
}
|
|
96
|
+
// Generate the PHP code
|
|
97
|
+
let code = '$client = new GuzzleHttp\\Client();\n\n';
|
|
98
|
+
if (Object.keys(options).length > 0) {
|
|
99
|
+
// Format the options array with proper indentation
|
|
100
|
+
const formattedOptions = objectToString(options);
|
|
101
|
+
code += `$response = $client->request('${method}', '${url}', ${formattedOptions});`;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
code += `$response = $client->request('${method}', '${url}');`;
|
|
105
|
+
}
|
|
106
|
+
return code;
|
|
107
|
+
},
|
|
87
108
|
};
|
|
88
|
-
//# sourceMappingURL=guzzle.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { restmethod } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { restmethod } from '../../../httpsnippet-lite/targets/powershell/restmethod/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* powershell/restmethod
|
|
5
|
+
*/
|
|
6
|
+
export const powershellRestmethod = {
|
|
7
|
+
target: 'powershell',
|
|
8
|
+
client: 'restmethod',
|
|
9
|
+
title: 'Invoke-RestMethod',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(restmethod, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
powershellRestmethod
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=restmethod.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { webrequest } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { webrequest } from '../../../httpsnippet-lite/targets/powershell/webrequest/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* powershell/webrequest
|
|
5
|
+
*/
|
|
6
|
+
export const powershellWebrequest = {
|
|
7
|
+
target: 'powershell',
|
|
8
|
+
client: 'webrequest',
|
|
9
|
+
title: 'Invoke-WebRequest',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(webrequest, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
powershellWebrequest
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=webrequest.js.map
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { requestsLikeGenerate } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { requestsLikeGenerate } from '../../../plugins/python/requestsLike.js';
|
|
2
|
+
/**
|
|
3
|
+
* python/httpx_async
|
|
4
|
+
*/
|
|
5
|
+
export const pythonHttpxAsync = {
|
|
6
|
+
target: 'python',
|
|
7
|
+
client: 'httpx_async',
|
|
8
|
+
title: 'HTTPX (Async)',
|
|
9
|
+
generate(request, configuration) {
|
|
10
|
+
let formattedReq = requestsLikeGenerate('await client', request, configuration);
|
|
11
|
+
// add indent
|
|
12
|
+
formattedReq = formattedReq
|
|
13
|
+
.split('\n')
|
|
14
|
+
.map((line) => (line.trim() === '' ? line : ' ' + line))
|
|
15
|
+
.join('\n');
|
|
16
|
+
return `async with httpx.AsyncClient() as client:\n${formattedReq}`;
|
|
17
|
+
},
|
|
12
18
|
};
|
|
13
|
-
export {
|
|
14
|
-
pythonHttpxAsync
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=async.js.map
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
pythonHttpxAsync,
|
|
5
|
-
pythonHttpxSync
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { pythonHttpxAsync } from './async.js';
|
|
2
|
+
export { pythonHttpxSync } from './sync.js';
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { requestsLikeGenerate } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { requestsLikeGenerate } from '../../../plugins/python/requestsLike.js';
|
|
2
|
+
/**
|
|
3
|
+
* python/httpx_sync
|
|
4
|
+
*/
|
|
5
|
+
export const pythonHttpxSync = {
|
|
6
|
+
target: 'python',
|
|
7
|
+
client: 'httpx_sync',
|
|
8
|
+
title: 'HTTPX (Sync)',
|
|
9
|
+
generate(request, configuration) {
|
|
10
|
+
return requestsLikeGenerate('httpx', request, configuration);
|
|
11
|
+
},
|
|
9
12
|
};
|
|
10
|
-
export {
|
|
11
|
-
pythonHttpxSync
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=sync.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { python3 } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { python3 } from '../../../httpsnippet-lite/targets/python/python3/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* python/python3
|
|
5
|
+
*/
|
|
6
|
+
export const pythonPython3 = {
|
|
7
|
+
target: 'python',
|
|
8
|
+
client: 'python3',
|
|
9
|
+
title: 'http.client',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(python3, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
pythonPython3
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=python3.js.map
|