@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.
Files changed (245) hide show
  1. package/dist/clients/index.js +168 -169
  2. package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
  3. package/dist/httpsnippet-lite/helpers/escape.js +69 -44
  4. package/dist/httpsnippet-lite/helpers/headers.js +17 -14
  5. package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
  6. package/dist/httpsnippet-lite/helpers/shell.js +13 -13
  7. package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
  8. package/dist/httpsnippet-lite/helpers/url.js +4 -8
  9. package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
  10. package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
  11. package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
  12. package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
  13. package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
  14. package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
  15. package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
  16. package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
  17. package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
  18. package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
  19. package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
  20. package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
  21. package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
  22. package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
  23. package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
  24. package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
  25. package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
  26. package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
  27. package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
  28. package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
  29. package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
  30. package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
  31. package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
  32. package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
  33. package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
  34. package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
  35. package/dist/httpsnippet-lite/targets/target.js +1 -1
  36. package/dist/index.js +2 -9
  37. package/dist/libs/http.js +68 -56
  38. package/dist/libs/javascript.js +77 -60
  39. package/dist/libs/php.js +59 -49
  40. package/dist/libs/rust.js +60 -33
  41. package/dist/libs/shell.js +14 -5
  42. package/dist/plugins/c/libcurl/index.js +1 -5
  43. package/dist/plugins/c/libcurl/libcurl.js +13 -13
  44. package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
  45. package/dist/plugins/clojure/clj_http/index.js +1 -5
  46. package/dist/plugins/csharp/httpclient/httpclient.js +186 -150
  47. package/dist/plugins/csharp/httpclient/index.js +1 -5
  48. package/dist/plugins/csharp/restsharp/index.js +1 -5
  49. package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
  50. package/dist/plugins/dart/http/http.js +95 -93
  51. package/dist/plugins/dart/http/index.js +1 -5
  52. package/dist/plugins/fsharp/httpclient/httpclient.js +156 -122
  53. package/dist/plugins/fsharp/httpclient/index.js +1 -5
  54. package/dist/plugins/go/native/index.js +1 -5
  55. package/dist/plugins/go/native/native.js +13 -13
  56. package/dist/plugins/http/http11/http11.js +103 -85
  57. package/dist/plugins/http/http11/index.js +1 -5
  58. package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
  59. package/dist/plugins/java/asynchttp/index.js +1 -5
  60. package/dist/plugins/java/nethttp/index.js +1 -5
  61. package/dist/plugins/java/nethttp/nethttp.js +13 -13
  62. package/dist/plugins/java/okhttp/index.js +1 -5
  63. package/dist/plugins/java/okhttp/okhttp.js +13 -13
  64. package/dist/plugins/java/unirest/index.js +1 -5
  65. package/dist/plugins/java/unirest/unirest.js +13 -13
  66. package/dist/plugins/js/axios/axios.js +13 -13
  67. package/dist/plugins/js/axios/index.js +1 -5
  68. package/dist/plugins/js/fetch/fetch.js +82 -68
  69. package/dist/plugins/js/fetch/index.js +1 -5
  70. package/dist/plugins/js/jquery/index.js +1 -5
  71. package/dist/plugins/js/jquery/jquery.js +13 -13
  72. package/dist/plugins/js/ofetch/index.js +1 -5
  73. package/dist/plugins/js/ofetch/ofetch.js +61 -48
  74. package/dist/plugins/js/xhr/index.js +1 -5
  75. package/dist/plugins/js/xhr/xhr.js +13 -13
  76. package/dist/plugins/kotlin/okhttp/index.js +1 -5
  77. package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
  78. package/dist/plugins/node/axios/axios.js +13 -13
  79. package/dist/plugins/node/axios/index.js +1 -5
  80. package/dist/plugins/node/fetch/fetch.js +86 -74
  81. package/dist/plugins/node/fetch/index.js +1 -5
  82. package/dist/plugins/node/ofetch/index.js +1 -5
  83. package/dist/plugins/node/ofetch/ofetch.js +61 -48
  84. package/dist/plugins/node/undici/index.js +1 -5
  85. package/dist/plugins/node/undici/undici.js +60 -47
  86. package/dist/plugins/objc/nsurlsession/index.js +1 -5
  87. package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
  88. package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
  89. package/dist/plugins/ocaml/cohttp/index.js +1 -5
  90. package/dist/plugins/php/curl/curl.js +143 -101
  91. package/dist/plugins/php/curl/index.js +1 -5
  92. package/dist/plugins/php/guzzle/guzzle.js +103 -83
  93. package/dist/plugins/php/guzzle/index.js +1 -5
  94. package/dist/plugins/powershell/restmethod/index.js +1 -5
  95. package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
  96. package/dist/plugins/powershell/webrequest/index.js +1 -5
  97. package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
  98. package/dist/plugins/python/httpx/async.js +17 -15
  99. package/dist/plugins/python/httpx/index.js +2 -7
  100. package/dist/plugins/python/httpx/sync.js +11 -12
  101. package/dist/plugins/python/python3/index.js +1 -5
  102. package/dist/plugins/python/python3/python3.js +13 -13
  103. package/dist/plugins/python/requests/index.js +1 -5
  104. package/dist/plugins/python/requests/requests.js +11 -12
  105. package/dist/plugins/python/requestsLike.js +128 -112
  106. package/dist/plugins/r/httr/httr.js +13 -13
  107. package/dist/plugins/r/httr/index.js +1 -5
  108. package/dist/plugins/ruby/native/index.js +1 -5
  109. package/dist/plugins/ruby/native/native.js +13 -13
  110. package/dist/plugins/rust/reqwest/index.js +1 -5
  111. package/dist/plugins/rust/reqwest/reqwest.js +110 -83
  112. package/dist/plugins/shell/curl/curl.js +128 -97
  113. package/dist/plugins/shell/curl/index.js +1 -5
  114. package/dist/plugins/shell/httpie/httpie.js +13 -13
  115. package/dist/plugins/shell/httpie/index.js +1 -5
  116. package/dist/plugins/shell/wget/index.js +1 -5
  117. package/dist/plugins/shell/wget/wget.js +13 -13
  118. package/dist/plugins/swift/nsurlsession/index.js +1 -5
  119. package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
  120. package/dist/snippetz.js +25 -28
  121. package/dist/utils/convertWithHttpSnippetLite.js +100 -96
  122. package/dist/utils/index.js +1 -5
  123. package/package.json +8 -12
  124. package/dist/clients/index.js.map +0 -7
  125. package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
  126. package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
  127. package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
  128. package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
  129. package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
  130. package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
  131. package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
  132. package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
  133. package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
  134. package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
  135. package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
  136. package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
  137. package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
  138. package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
  139. package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
  140. package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
  141. package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
  142. package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
  143. package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
  144. package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
  145. package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
  146. package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
  147. package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
  148. package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
  149. package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
  150. package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
  151. package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
  152. package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
  153. package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
  154. package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
  155. package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
  156. package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
  157. package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
  158. package/dist/httpsnippet-lite/targets/target.js.map +0 -7
  159. package/dist/index.js.map +0 -7
  160. package/dist/libs/http.js.map +0 -7
  161. package/dist/libs/javascript.js.map +0 -7
  162. package/dist/libs/php.js.map +0 -7
  163. package/dist/libs/rust.js.map +0 -7
  164. package/dist/libs/shell.js.map +0 -7
  165. package/dist/plugins/c/libcurl/index.js.map +0 -7
  166. package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
  167. package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
  168. package/dist/plugins/clojure/clj_http/index.js.map +0 -7
  169. package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
  170. package/dist/plugins/csharp/httpclient/index.js.map +0 -7
  171. package/dist/plugins/csharp/restsharp/index.js.map +0 -7
  172. package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
  173. package/dist/plugins/dart/http/http.js.map +0 -7
  174. package/dist/plugins/dart/http/index.js.map +0 -7
  175. package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
  176. package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
  177. package/dist/plugins/go/native/index.js.map +0 -7
  178. package/dist/plugins/go/native/native.js.map +0 -7
  179. package/dist/plugins/http/http11/http11.js.map +0 -7
  180. package/dist/plugins/http/http11/index.js.map +0 -7
  181. package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
  182. package/dist/plugins/java/asynchttp/index.js.map +0 -7
  183. package/dist/plugins/java/nethttp/index.js.map +0 -7
  184. package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
  185. package/dist/plugins/java/okhttp/index.js.map +0 -7
  186. package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
  187. package/dist/plugins/java/unirest/index.js.map +0 -7
  188. package/dist/plugins/java/unirest/unirest.js.map +0 -7
  189. package/dist/plugins/js/axios/axios.js.map +0 -7
  190. package/dist/plugins/js/axios/index.js.map +0 -7
  191. package/dist/plugins/js/fetch/fetch.js.map +0 -7
  192. package/dist/plugins/js/fetch/index.js.map +0 -7
  193. package/dist/plugins/js/jquery/index.js.map +0 -7
  194. package/dist/plugins/js/jquery/jquery.js.map +0 -7
  195. package/dist/plugins/js/ofetch/index.js.map +0 -7
  196. package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
  197. package/dist/plugins/js/xhr/index.js.map +0 -7
  198. package/dist/plugins/js/xhr/xhr.js.map +0 -7
  199. package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
  200. package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
  201. package/dist/plugins/node/axios/axios.js.map +0 -7
  202. package/dist/plugins/node/axios/index.js.map +0 -7
  203. package/dist/plugins/node/fetch/fetch.js.map +0 -7
  204. package/dist/plugins/node/fetch/index.js.map +0 -7
  205. package/dist/plugins/node/ofetch/index.js.map +0 -7
  206. package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
  207. package/dist/plugins/node/undici/index.js.map +0 -7
  208. package/dist/plugins/node/undici/undici.js.map +0 -7
  209. package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
  210. package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
  211. package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
  212. package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
  213. package/dist/plugins/php/curl/curl.js.map +0 -7
  214. package/dist/plugins/php/curl/index.js.map +0 -7
  215. package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
  216. package/dist/plugins/php/guzzle/index.js.map +0 -7
  217. package/dist/plugins/powershell/restmethod/index.js.map +0 -7
  218. package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
  219. package/dist/plugins/powershell/webrequest/index.js.map +0 -7
  220. package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
  221. package/dist/plugins/python/httpx/async.js.map +0 -7
  222. package/dist/plugins/python/httpx/index.js.map +0 -7
  223. package/dist/plugins/python/httpx/sync.js.map +0 -7
  224. package/dist/plugins/python/python3/index.js.map +0 -7
  225. package/dist/plugins/python/python3/python3.js.map +0 -7
  226. package/dist/plugins/python/requests/index.js.map +0 -7
  227. package/dist/plugins/python/requests/requests.js.map +0 -7
  228. package/dist/plugins/python/requestsLike.js.map +0 -7
  229. package/dist/plugins/r/httr/httr.js.map +0 -7
  230. package/dist/plugins/r/httr/index.js.map +0 -7
  231. package/dist/plugins/ruby/native/index.js.map +0 -7
  232. package/dist/plugins/ruby/native/native.js.map +0 -7
  233. package/dist/plugins/rust/reqwest/index.js.map +0 -7
  234. package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
  235. package/dist/plugins/shell/curl/curl.js.map +0 -7
  236. package/dist/plugins/shell/curl/index.js.map +0 -7
  237. package/dist/plugins/shell/httpie/httpie.js.map +0 -7
  238. package/dist/plugins/shell/httpie/index.js.map +0 -7
  239. package/dist/plugins/shell/wget/index.js.map +0 -7
  240. package/dist/plugins/shell/wget/wget.js.map +0 -7
  241. package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
  242. package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
  243. package/dist/snippetz.js.map +0 -7
  244. package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
  245. package/dist/utils/index.js.map +0 -7
@@ -1,104 +1,146 @@
1
- import { objectToString } from "../../../libs/php.js";
2
- const phpCurl = {
3
- target: "php",
4
- client: "curl",
5
- title: "cURL",
6
- generate(request, configuration) {
7
- const normalizedRequest = {
8
- method: "GET",
9
- ...request
10
- };
11
- normalizedRequest.method = normalizedRequest.method.toUpperCase();
12
- const parts = [];
13
- const queryString = normalizedRequest.queryString?.length ? "?" + normalizedRequest.queryString.map((param) => {
14
- const encodedName = encodeURIComponent(param.name);
15
- const encodedValue = encodeURIComponent(param.value);
16
- return `${encodedName}=${encodedValue}`;
17
- }).join("&") : "";
18
- const url = `${normalizedRequest.url}${queryString}`;
19
- parts.push(`$ch = curl_init("${url}");`);
20
- parts.push("");
21
- if (normalizedRequest.method === "POST") {
22
- parts.push("curl_setopt($ch, CURLOPT_POST, true);");
23
- }
24
- if (configuration?.auth?.username && configuration?.auth?.password) {
25
- parts.push(`curl_setopt($ch, CURLOPT_USERPWD, '${configuration.auth.username}:${configuration.auth.password}');`);
26
- }
27
- const allHeaders = [...normalizedRequest.headers || []];
28
- const hasContentType = () => allHeaders.some((h) => h.name.toLowerCase() === "content-type");
29
- if (normalizedRequest.postData) {
30
- if (normalizedRequest.postData.mimeType === "multipart/form-data" && normalizedRequest.postData.params && !hasContentType()) {
31
- allHeaders.push({ name: "Content-Type", value: "multipart/form-data" });
32
- } else if (normalizedRequest.postData.mimeType === "application/x-www-form-urlencoded" && normalizedRequest.postData.params && !hasContentType()) {
33
- allHeaders.push({ name: "Content-Type", value: "application/x-www-form-urlencoded" });
34
- } else if (normalizedRequest.postData.mimeType === "application/octet-stream" && !hasContentType()) {
35
- allHeaders.push({ name: "Content-Type", value: "application/octet-stream" });
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
- } else if (normalizedRequest.postData.mimeType === "multipart/form-data" && normalizedRequest.postData.params) {
66
- const formData = normalizedRequest.postData.params.reduce((acc, param) => {
67
- if (param.fileName !== void 0) {
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
- parts.push("");
95
- parts.push("curl_exec($ch);");
96
- parts.push("");
97
- parts.push("curl_close($ch);");
98
- return parts.join("\n").replace(/\n\n\n/g, "\n\n");
99
- }
100
- };
101
- export {
102
- phpCurl
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,5 +1 @@
1
- import { phpCurl } from "./curl.js";
2
- export {
3
- phpCurl
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { phpCurl } from './curl.js';
@@ -1,88 +1,108 @@
1
- import { reduceQueryParams } from "../../../libs/http.js";
2
- import { Raw, objectToString } from "../../../libs/php.js";
3
- const phpGuzzle = {
4
- target: "php",
5
- client: "guzzle",
6
- title: "Guzzle",
7
- generate(request, configuration) {
8
- if (!request) {
9
- return "";
10
- }
11
- const options = {};
12
- const method = (request.method || "GET").toUpperCase();
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
- options.headers = headers;
26
- }
27
- if (request.queryString && request.queryString.length > 0) {
28
- options.query = reduceQueryParams(request.queryString);
29
- }
30
- if (request.cookies && request.cookies.length > 0) {
31
- const cookies = {};
32
- request.cookies.forEach((cookie) => {
33
- cookies[cookie.name] = cookie.value;
34
- });
35
- options.cookies = cookies;
36
- }
37
- if (configuration?.auth?.username && configuration.auth.password) {
38
- options.auth = [configuration.auth.username, configuration.auth.password];
39
- }
40
- if (request.postData) {
41
- if (request.postData.mimeType === "application/json") {
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
- } else if (request.postData.mimeType === "multipart/form-data") {
48
- if (request.postData.params) {
49
- options.multipart = request.postData.params.map((param) => ({
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
- } else if (request.postData.mimeType === "application/x-www-form-urlencoded") {
61
- if (request.postData.params) {
62
- const formParams = {};
63
- request.postData.params.forEach((param) => {
64
- formParams[param.name] = param.value || "";
65
- });
66
- options.form_params = formParams;
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
- } else {
69
- options.body = request.postData.text;
70
- }
71
- }
72
- if (request.headers && Array.isArray(request.headers) && request.headers.some((h) => h.name === "Accept-Encoding" && h.value.includes("gzip"))) {
73
- options.decode_content = true;
74
- }
75
- let code = "$client = new GuzzleHttp\\Client();\n\n";
76
- if (Object.keys(options).length > 0) {
77
- const formattedOptions = objectToString(options);
78
- code += `$response = $client->request('${method}', '${url}', ${formattedOptions});`;
79
- } else {
80
- code += `$response = $client->request('${method}', '${url}');`;
81
- }
82
- return code;
83
- }
84
- };
85
- export {
86
- phpGuzzle
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,5 +1 @@
1
- import { phpGuzzle } from "./guzzle.js";
2
- export {
3
- phpGuzzle
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { phpGuzzle } from './guzzle.js';
@@ -1,5 +1 @@
1
- import { powershellRestmethod } from "./restmethod.js";
2
- export {
3
- powershellRestmethod
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { powershellRestmethod } from './restmethod.js';
@@ -1,14 +1,14 @@
1
- import { restmethod } from "../../../httpsnippet-lite/targets/powershell/restmethod/client.js";
2
- import { convertWithHttpSnippetLite } from "../../../utils/convertWithHttpSnippetLite.js";
3
- const powershellRestmethod = {
4
- target: "powershell",
5
- client: "restmethod",
6
- title: "Invoke-RestMethod",
7
- generate(request) {
8
- return convertWithHttpSnippetLite(restmethod, request);
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,5 +1 @@
1
- import { powershellWebrequest } from "./webrequest.js";
2
- export {
3
- powershellWebrequest
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { powershellWebrequest } from './webrequest.js';
@@ -1,14 +1,14 @@
1
- import { webrequest } from "../../../httpsnippet-lite/targets/powershell/webrequest/client.js";
2
- import { convertWithHttpSnippetLite } from "../../../utils/convertWithHttpSnippetLite.js";
3
- const powershellWebrequest = {
4
- target: "powershell",
5
- client: "webrequest",
6
- title: "Invoke-WebRequest",
7
- generate(request) {
8
- return convertWithHttpSnippetLite(webrequest, request);
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 "../../../plugins/python/requestsLike.js";
2
- const pythonHttpxAsync = {
3
- target: "python",
4
- client: "httpx_async",
5
- title: "HTTPX (Async)",
6
- generate(request, configuration) {
7
- let formattedReq = requestsLikeGenerate("await client", request, configuration);
8
- formattedReq = formattedReq.split("\n").map((line) => line.trim() === "" ? line : " " + line).join("\n");
9
- return `async with httpx.AsyncClient() as client:
10
- ${formattedReq}`;
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
- import { pythonHttpxAsync } from "./async.js";
2
- import { pythonHttpxSync } from "./sync.js";
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 "../../../plugins/python/requestsLike.js";
2
- const pythonHttpxSync = {
3
- target: "python",
4
- client: "httpx_sync",
5
- title: "HTTPX (Sync)",
6
- generate(request, configuration) {
7
- return requestsLikeGenerate("httpx", request, configuration);
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,5 +1 @@
1
- import { pythonPython3 } from "./python3.js";
2
- export {
3
- pythonPython3
4
- };
5
- //# sourceMappingURL=index.js.map
1
+ export { pythonPython3 } from './python3.js';
@@ -1,14 +1,14 @@
1
- import { python3 } from "../../../httpsnippet-lite/targets/python/python3/client.js";
2
- import { convertWithHttpSnippetLite } from "../../../utils/convertWithHttpSnippetLite.js";
3
- const pythonPython3 = {
4
- target: "python",
5
- client: "python3",
6
- title: "http.client",
7
- generate(request) {
8
- return convertWithHttpSnippetLite(python3, request);
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