@scalar/snippetz 0.3.0 → 0.3.1
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.d.ts.map +1 -1
- package/dist/clients.js +2 -1
- package/dist/clients.js.map +2 -2
- package/dist/plugins/python/httpx/async.d.ts +6 -0
- package/dist/plugins/python/httpx/async.d.ts.map +1 -0
- package/dist/plugins/python/httpx/async.js +16 -0
- package/dist/plugins/python/httpx/async.js.map +7 -0
- package/dist/plugins/python/httpx/index.d.ts +3 -0
- package/dist/plugins/python/httpx/index.d.ts.map +1 -0
- package/dist/plugins/python/httpx/index.js +3 -0
- package/dist/plugins/python/httpx/index.js.map +7 -0
- package/dist/plugins/python/httpx/sync.d.ts +6 -0
- package/dist/plugins/python/httpx/sync.d.ts.map +1 -0
- package/dist/plugins/python/httpx/sync.js +13 -0
- package/dist/plugins/python/httpx/sync.js.map +7 -0
- package/dist/plugins/python/requests/requests.d.ts.map +1 -1
- package/dist/plugins/python/requests/requests.js +2 -93
- package/dist/plugins/python/requests/requests.js.map +3 -3
- package/dist/plugins/python/requestsLike.d.ts +3 -0
- package/dist/plugins/python/requestsLike.d.ts.map +1 -0
- package/dist/plugins/python/requestsLike.js +120 -0
- package/dist/plugins/python/requestsLike.js.map +7 -0
- package/dist/snippetz.d.ts +1 -1
- package/package.json +8 -3
- package/dist/plugins/c/libcurl/libcurl.test.js +0 -208
- package/dist/plugins/c/libcurl/libcurl.test.js.map +0 -7
- package/dist/plugins/clojure/clj_http/clj_http.test.js +0 -151
- package/dist/plugins/clojure/clj_http/clj_http.test.js.map +0 -7
- package/dist/plugins/dart/http/http.test.js +0 -550
- package/dist/plugins/dart/http/http.test.js.map +0 -7
- package/dist/plugins/go/native/native.test.js +0 -366
- package/dist/plugins/go/native/native.test.js.map +0 -7
- package/dist/plugins/http/http11/http11.test.js +0 -175
- package/dist/plugins/http/http11/http11.test.js.map +0 -7
- package/dist/plugins/java/okhttp/okhttp.test.js +0 -164
- package/dist/plugins/java/okhttp/okhttp.test.js.map +0 -7
- package/dist/plugins/js/fetch/fetch.test.js +0 -214
- package/dist/plugins/js/fetch/fetch.test.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.test.js +0 -126
- package/dist/plugins/js/ofetch/ofetch.test.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/okhttp.test.js +0 -164
- package/dist/plugins/kotlin/okhttp/okhttp.test.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.test.js +0 -200
- package/dist/plugins/node/fetch/fetch.test.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.test.js +0 -126
- package/dist/plugins/node/ofetch/ofetch.test.js.map +0 -7
- package/dist/plugins/node/undici/undici.test.js +0 -133
- package/dist/plugins/node/undici/undici.test.js.map +0 -7
- package/dist/plugins/php/curl/curl.test.js +0 -564
- package/dist/plugins/php/curl/curl.test.js.map +0 -7
- package/dist/plugins/php/guzzle/guzzle.test.js +0 -546
- package/dist/plugins/php/guzzle/guzzle.test.js.map +0 -7
- package/dist/plugins/python/requests/requests.test.js +0 -419
- package/dist/plugins/python/requests/requests.test.js.map +0 -7
- package/dist/plugins/ruby/native/native.test.js +0 -240
- package/dist/plugins/ruby/native/native.test.js.map +0 -7
- package/dist/plugins/shell/curl/curl.test.js +0 -427
- package/dist/plugins/shell/curl/curl.test.js.map +0 -7
- package/dist/plugins/shell/httpie/httpie.test.js +0 -113
- package/dist/plugins/shell/httpie/httpie.test.js.map +0 -7
- package/dist/plugins/shell/wget/wget.test.js +0 -143
- package/dist/plugins/shell/wget/wget.test.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/nsurlsession.test.js +0 -344
- package/dist/plugins/swift/nsurlsession/nsurlsession.test.js.map +0 -7
- package/dist/snippetz.test.js +0 -79
- package/dist/snippetz.test.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.test.js +0 -106
- package/dist/utils/convertWithHttpSnippetLite.test.js.map +0 -7
- package/dist/utils/create-search-params.test.js +0 -49
- package/dist/utils/create-search-params.test.js.map +0 -7
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/plugins/node/undici/undici.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { nodeUndici } from './undici'\n\ndescribe('nodeUndici', () => {\n it('has import', () => {\n const result = nodeUndici.generate({\n url: 'https://example.com',\n })\n\n expect(result).toContain(`import { request } from 'undici'`)\n })\n\n it('returns a basic request', () => {\n const result = nodeUndici.generate({\n url: 'https://example.com',\n })\n\n expect(result).toBe(`import { request } from 'undici'\n\nconst { statusCode, body } = await request('https://example.com')`)\n })\n\n it('returns a POST request', () => {\n const result = nodeUndici.generate({\n url: 'https://example.com',\n method: 'post',\n })\n\n expect(result).toBe(`import { request } from 'undici'\n\nconst { statusCode, body } = await request('https://example.com', {\n method: 'POST'\n})`)\n })\n\n it('has headers', () => {\n const result = nodeUndici.generate({\n url: 'https://example.com',\n headers: [\n {\n name: 'Content-Type',\n value: 'application/json',\n },\n ],\n })\n\n expect(result).toBe(`import { request } from 'undici'\n\nconst { statusCode, body } = await request('https://example.com', {\n headers: {\n 'Content-Type': 'application/json'\n }\n})`)\n })\n\n it('doesn\u2019t add empty headers', () => {\n const result = nodeUndici.generate({\n url: 'https://example.com',\n headers: [],\n })\n\n expect(result).toBe(`import { request } from 'undici'\n\nconst { statusCode, body } = await request('https://example.com')`)\n })\n\n it('has JSON body', () => {\n const result = nodeUndici.generate({\n url: 'https://example.com',\n headers: [\n {\n name: 'Content-Type',\n value: 'application/json',\n },\n ],\n postData: {\n mimeType: 'application/json',\n text: JSON.stringify({\n hello: 'world',\n }),\n },\n })\n\n expect(result).toBe(`import { request } from 'undici'\n\nconst { statusCode, body } = await request('https://example.com', {\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n hello: 'world'\n })\n})`)\n })\n\n it('has query string', () => {\n const result = nodeUndici.generate({\n url: 'https://example.com',\n queryString: [\n {\n name: 'foo',\n value: 'bar',\n },\n {\n name: 'bar',\n value: 'foo',\n },\n ],\n })\n\n expect(result).toBe(`import { request } from 'undici'\n\nconst { statusCode, body } = await request('https://example.com?foo=bar&bar=foo')`)\n })\n\n it('has cookies', () => {\n const result = nodeUndici.generate({\n url: 'https://example.com',\n cookies: [\n {\n name: 'foo',\n value: 'bar',\n },\n {\n name: 'bar',\n value: 'foo',\n },\n ],\n })\n\n expect(result).toBe(`import { request } from 'undici'\n\nconst { statusCode, body } = await request('https://example.com', {\n headers: {\n 'Set-Cookie': 'foo=bar; bar=foo'\n }\n})`)\n })\n\n it('doesn\u2019t add empty cookies', () => {\n const result = nodeUndici.generate({\n url: 'https://example.com',\n cookies: [],\n })\n\n expect(result).toBe(`import { request } from 'undici'\n\nconst { statusCode, body } = await request('https://example.com')`)\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,kBAAkB;AAE3B,SAAS,cAAc,MAAM;AAC3B,KAAG,cAAc,MAAM;AACrB,UAAM,SAAS,WAAW,SAAS;AAAA,MACjC,KAAK;AAAA,IACP,CAAC;AAED,WAAO,MAAM,EAAE,UAAU,kCAAkC;AAAA,EAC7D,CAAC;AAED,KAAG,2BAA2B,MAAM;AAClC,UAAM,SAAS,WAAW,SAAS;AAAA,MACjC,KAAK;AAAA,IACP,CAAC;AAED,WAAO,MAAM,EAAE,KAAK;AAAA;AAAA,kEAE0C;AAAA,EAChE,CAAC;AAED,KAAG,0BAA0B,MAAM;AACjC,UAAM,SAAS,WAAW,SAAS;AAAA,MACjC,KAAK;AAAA,MACL,QAAQ;AAAA,IACV,CAAC;AAED,WAAO,MAAM,EAAE,KAAK;AAAA;AAAA;AAAA;AAAA,GAIrB;AAAA,EACD,CAAC;AAED,KAAG,eAAe,MAAM;AACtB,UAAM,SAAS,WAAW,SAAS;AAAA,MACjC,KAAK;AAAA,MACL,SAAS;AAAA,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AAA,MACF;AAAA,IACF,CAAC;AAED,WAAO,MAAM,EAAE,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAMrB;AAAA,EACD,CAAC;AAED,KAAG,kCAA6B,MAAM;AACpC,UAAM,SAAS,WAAW,SAAS;AAAA,MACjC,KAAK;AAAA,MACL,SAAS,CAAC;AAAA,IACZ,CAAC;AAED,WAAO,MAAM,EAAE,KAAK;AAAA;AAAA,kEAE0C;AAAA,EAChE,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,564 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { phpCurl } from "./curl.js";
|
|
3
|
-
describe("phpCurl", () => {
|
|
4
|
-
it("returns a basic request", () => {
|
|
5
|
-
const result = phpCurl.generate({
|
|
6
|
-
url: "https://example.com"
|
|
7
|
-
});
|
|
8
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
9
|
-
|
|
10
|
-
curl_exec($ch);
|
|
11
|
-
|
|
12
|
-
curl_close($ch);`);
|
|
13
|
-
});
|
|
14
|
-
it("returns a POST request", () => {
|
|
15
|
-
const result = phpCurl.generate({
|
|
16
|
-
url: "https://example.com",
|
|
17
|
-
method: "post"
|
|
18
|
-
});
|
|
19
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
20
|
-
|
|
21
|
-
curl_setopt($ch, CURLOPT_POST, true);
|
|
22
|
-
|
|
23
|
-
curl_exec($ch);
|
|
24
|
-
|
|
25
|
-
curl_close($ch);`);
|
|
26
|
-
});
|
|
27
|
-
it("has headers", () => {
|
|
28
|
-
const result = phpCurl.generate({
|
|
29
|
-
url: "https://example.com",
|
|
30
|
-
headers: [
|
|
31
|
-
{
|
|
32
|
-
name: "Content-Type",
|
|
33
|
-
value: "application/json"
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
});
|
|
37
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
38
|
-
|
|
39
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
|
40
|
-
|
|
41
|
-
curl_exec($ch);
|
|
42
|
-
|
|
43
|
-
curl_close($ch);`);
|
|
44
|
-
});
|
|
45
|
-
it("doesn't add empty headers", () => {
|
|
46
|
-
const result = phpCurl.generate({
|
|
47
|
-
url: "https://example.com",
|
|
48
|
-
headers: []
|
|
49
|
-
});
|
|
50
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
51
|
-
|
|
52
|
-
curl_exec($ch);
|
|
53
|
-
|
|
54
|
-
curl_close($ch);`);
|
|
55
|
-
});
|
|
56
|
-
it("has JSON body with PHP array", () => {
|
|
57
|
-
const result = phpCurl.generate({
|
|
58
|
-
url: "https://example.com",
|
|
59
|
-
method: "POST",
|
|
60
|
-
headers: [
|
|
61
|
-
{
|
|
62
|
-
name: "Content-Type",
|
|
63
|
-
value: "application/json"
|
|
64
|
-
}
|
|
65
|
-
],
|
|
66
|
-
postData: {
|
|
67
|
-
mimeType: "application/json",
|
|
68
|
-
text: JSON.stringify({
|
|
69
|
-
hello: "world"
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
74
|
-
|
|
75
|
-
curl_setopt($ch, CURLOPT_POST, true);
|
|
76
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
|
77
|
-
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
|
78
|
-
'hello' => 'world'
|
|
79
|
-
]));
|
|
80
|
-
|
|
81
|
-
curl_exec($ch);
|
|
82
|
-
|
|
83
|
-
curl_close($ch);`);
|
|
84
|
-
});
|
|
85
|
-
it("has query string", () => {
|
|
86
|
-
const result = phpCurl.generate({
|
|
87
|
-
url: "https://example.com",
|
|
88
|
-
queryString: [
|
|
89
|
-
{
|
|
90
|
-
name: "foo",
|
|
91
|
-
value: "bar"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: "bar",
|
|
95
|
-
value: "foo"
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
});
|
|
99
|
-
expect(result).toBe(`$ch = curl_init("https://example.com?foo=bar&bar=foo");
|
|
100
|
-
|
|
101
|
-
curl_exec($ch);
|
|
102
|
-
|
|
103
|
-
curl_close($ch);`);
|
|
104
|
-
});
|
|
105
|
-
it("has cookies", () => {
|
|
106
|
-
const result = phpCurl.generate({
|
|
107
|
-
url: "https://example.com",
|
|
108
|
-
cookies: [
|
|
109
|
-
{
|
|
110
|
-
name: "foo",
|
|
111
|
-
value: "bar"
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: "bar",
|
|
115
|
-
value: "foo"
|
|
116
|
-
}
|
|
117
|
-
]
|
|
118
|
-
});
|
|
119
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
120
|
-
|
|
121
|
-
curl_setopt($ch, CURLOPT_COOKIE, 'foo=bar; bar=foo');
|
|
122
|
-
|
|
123
|
-
curl_exec($ch);
|
|
124
|
-
|
|
125
|
-
curl_close($ch);`);
|
|
126
|
-
});
|
|
127
|
-
it("doesn't add empty cookies", () => {
|
|
128
|
-
const result = phpCurl.generate({
|
|
129
|
-
url: "https://example.com",
|
|
130
|
-
cookies: []
|
|
131
|
-
});
|
|
132
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
133
|
-
|
|
134
|
-
curl_exec($ch);
|
|
135
|
-
|
|
136
|
-
curl_close($ch);`);
|
|
137
|
-
});
|
|
138
|
-
it("adds basic auth credentials", () => {
|
|
139
|
-
const result = phpCurl.generate(
|
|
140
|
-
{
|
|
141
|
-
url: "https://example.com"
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
auth: {
|
|
145
|
-
username: "user",
|
|
146
|
-
password: "pass"
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
151
|
-
|
|
152
|
-
curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
|
|
153
|
-
|
|
154
|
-
curl_exec($ch);
|
|
155
|
-
|
|
156
|
-
curl_close($ch);`);
|
|
157
|
-
});
|
|
158
|
-
it("omits auth when not provided", () => {
|
|
159
|
-
const result = phpCurl.generate({
|
|
160
|
-
url: "https://example.com"
|
|
161
|
-
});
|
|
162
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
163
|
-
|
|
164
|
-
curl_exec($ch);
|
|
165
|
-
|
|
166
|
-
curl_close($ch);`);
|
|
167
|
-
});
|
|
168
|
-
it("omits auth when username is missing", () => {
|
|
169
|
-
const result = phpCurl.generate(
|
|
170
|
-
{
|
|
171
|
-
url: "https://example.com"
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
auth: {
|
|
175
|
-
username: "",
|
|
176
|
-
password: "pass"
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
);
|
|
180
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
181
|
-
|
|
182
|
-
curl_exec($ch);
|
|
183
|
-
|
|
184
|
-
curl_close($ch);`);
|
|
185
|
-
});
|
|
186
|
-
it("omits auth when password is missing", () => {
|
|
187
|
-
const result = phpCurl.generate(
|
|
188
|
-
{
|
|
189
|
-
url: "https://example.com"
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
auth: {
|
|
193
|
-
username: "user",
|
|
194
|
-
password: ""
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
);
|
|
198
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
199
|
-
|
|
200
|
-
curl_exec($ch);
|
|
201
|
-
|
|
202
|
-
curl_close($ch);`);
|
|
203
|
-
});
|
|
204
|
-
it("handles special characters in auth credentials", () => {
|
|
205
|
-
const result = phpCurl.generate(
|
|
206
|
-
{
|
|
207
|
-
url: "https://example.com"
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
auth: {
|
|
211
|
-
username: "user@example.com",
|
|
212
|
-
password: "pass:word!"
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
217
|
-
|
|
218
|
-
curl_setopt($ch, CURLOPT_USERPWD, 'user@example.com:pass:word!');
|
|
219
|
-
|
|
220
|
-
curl_exec($ch);
|
|
221
|
-
|
|
222
|
-
curl_close($ch);`);
|
|
223
|
-
});
|
|
224
|
-
it("handles undefined auth object", () => {
|
|
225
|
-
const result = phpCurl.generate(
|
|
226
|
-
{
|
|
227
|
-
url: "https://example.com"
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
auth: void 0
|
|
231
|
-
}
|
|
232
|
-
);
|
|
233
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
234
|
-
|
|
235
|
-
curl_exec($ch);
|
|
236
|
-
|
|
237
|
-
curl_close($ch);`);
|
|
238
|
-
});
|
|
239
|
-
it("handles multipart form data with files", () => {
|
|
240
|
-
const result = phpCurl.generate({
|
|
241
|
-
url: "https://example.com",
|
|
242
|
-
method: "POST",
|
|
243
|
-
postData: {
|
|
244
|
-
mimeType: "multipart/form-data",
|
|
245
|
-
params: [
|
|
246
|
-
{
|
|
247
|
-
name: "file",
|
|
248
|
-
fileName: "test.txt"
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
name: "field",
|
|
252
|
-
value: "value"
|
|
253
|
-
}
|
|
254
|
-
]
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
258
|
-
|
|
259
|
-
curl_setopt($ch, CURLOPT_POST, true);
|
|
260
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
|
|
261
|
-
curl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => '@test.txt', 'field' => 'value']);
|
|
262
|
-
|
|
263
|
-
curl_exec($ch);
|
|
264
|
-
|
|
265
|
-
curl_close($ch);`);
|
|
266
|
-
});
|
|
267
|
-
it("handles multipart form data with JSON payload", () => {
|
|
268
|
-
const result = phpCurl.generate({
|
|
269
|
-
url: "https://example.com",
|
|
270
|
-
method: "POST",
|
|
271
|
-
headers: [
|
|
272
|
-
{
|
|
273
|
-
name: "Content-Type",
|
|
274
|
-
value: "multipart/form-data"
|
|
275
|
-
}
|
|
276
|
-
],
|
|
277
|
-
postData: {
|
|
278
|
-
mimeType: "multipart/form-data",
|
|
279
|
-
text: JSON.stringify({
|
|
280
|
-
foo: "bar"
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
285
|
-
|
|
286
|
-
curl_setopt($ch, CURLOPT_POST, true);
|
|
287
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
|
|
288
|
-
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
|
289
|
-
'foo' => 'bar'
|
|
290
|
-
]));
|
|
291
|
-
|
|
292
|
-
curl_exec($ch);
|
|
293
|
-
|
|
294
|
-
curl_close($ch);`);
|
|
295
|
-
});
|
|
296
|
-
it("handles url-encoded form data with special characters", () => {
|
|
297
|
-
const result = phpCurl.generate({
|
|
298
|
-
url: "https://example.com",
|
|
299
|
-
method: "POST",
|
|
300
|
-
postData: {
|
|
301
|
-
mimeType: "application/x-www-form-urlencoded",
|
|
302
|
-
params: [
|
|
303
|
-
{
|
|
304
|
-
name: "special chars!@#",
|
|
305
|
-
value: "value"
|
|
306
|
-
}
|
|
307
|
-
]
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
311
|
-
|
|
312
|
-
curl_setopt($ch, CURLOPT_POST, true);
|
|
313
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
|
|
314
|
-
curl_setopt($ch, CURLOPT_POSTFIELDS, 'special%20chars!%40%23=value');
|
|
315
|
-
|
|
316
|
-
curl_exec($ch);
|
|
317
|
-
|
|
318
|
-
curl_close($ch);`);
|
|
319
|
-
});
|
|
320
|
-
it("handles binary data flag", () => {
|
|
321
|
-
const result = phpCurl.generate({
|
|
322
|
-
url: "https://example.com",
|
|
323
|
-
method: "POST",
|
|
324
|
-
postData: {
|
|
325
|
-
mimeType: "application/octet-stream",
|
|
326
|
-
text: "binary content"
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
330
|
-
|
|
331
|
-
curl_setopt($ch, CURLOPT_POST, true);
|
|
332
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/octet-stream']);
|
|
333
|
-
curl_setopt($ch, CURLOPT_POSTFIELDS, 'binary content');
|
|
334
|
-
|
|
335
|
-
curl_exec($ch);
|
|
336
|
-
|
|
337
|
-
curl_close($ch);`);
|
|
338
|
-
});
|
|
339
|
-
it("handles compressed response", () => {
|
|
340
|
-
const result = phpCurl.generate({
|
|
341
|
-
url: "https://example.com",
|
|
342
|
-
headers: [
|
|
343
|
-
{
|
|
344
|
-
name: "Accept-Encoding",
|
|
345
|
-
value: "gzip, deflate"
|
|
346
|
-
}
|
|
347
|
-
]
|
|
348
|
-
});
|
|
349
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
350
|
-
|
|
351
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept-Encoding: gzip, deflate']);
|
|
352
|
-
curl_setopt($ch, CURLOPT_ENCODING, '');
|
|
353
|
-
|
|
354
|
-
curl_exec($ch);
|
|
355
|
-
|
|
356
|
-
curl_close($ch);`);
|
|
357
|
-
});
|
|
358
|
-
it("handles special characters in URL", () => {
|
|
359
|
-
const result = phpCurl.generate({
|
|
360
|
-
url: "https://example.com/path with spaces/[brackets]"
|
|
361
|
-
});
|
|
362
|
-
expect(result).toBe(`$ch = curl_init("https://example.com/path with spaces/[brackets]");
|
|
363
|
-
|
|
364
|
-
curl_exec($ch);
|
|
365
|
-
|
|
366
|
-
curl_close($ch);`);
|
|
367
|
-
});
|
|
368
|
-
it("handles special characters in query parameters", () => {
|
|
369
|
-
const result = phpCurl.generate({
|
|
370
|
-
url: "https://example.com",
|
|
371
|
-
queryString: [
|
|
372
|
-
{
|
|
373
|
-
name: "q",
|
|
374
|
-
value: "hello world & more"
|
|
375
|
-
},
|
|
376
|
-
{
|
|
377
|
-
name: "special",
|
|
378
|
-
value: "!@#$%^&*()"
|
|
379
|
-
}
|
|
380
|
-
]
|
|
381
|
-
});
|
|
382
|
-
expect(
|
|
383
|
-
result
|
|
384
|
-
).toBe(`$ch = curl_init("https://example.com?q=hello%20world%20%26%20more&special=!%40%23%24%25%5E%26*()");
|
|
385
|
-
|
|
386
|
-
curl_exec($ch);
|
|
387
|
-
|
|
388
|
-
curl_close($ch);`);
|
|
389
|
-
});
|
|
390
|
-
it("handles empty URL", () => {
|
|
391
|
-
const result = phpCurl.generate({
|
|
392
|
-
url: ""
|
|
393
|
-
});
|
|
394
|
-
expect(result).toBe(`$ch = curl_init("");
|
|
395
|
-
|
|
396
|
-
curl_exec($ch);
|
|
397
|
-
|
|
398
|
-
curl_close($ch);`);
|
|
399
|
-
});
|
|
400
|
-
it("handles extremely long URLs", () => {
|
|
401
|
-
const result = phpCurl.generate({
|
|
402
|
-
url: "https://example.com/" + "a".repeat(2e3)
|
|
403
|
-
});
|
|
404
|
-
expect(result).toBe(`$ch = curl_init("https://example.com/${"a".repeat(2e3)}");
|
|
405
|
-
|
|
406
|
-
curl_exec($ch);
|
|
407
|
-
|
|
408
|
-
curl_close($ch);`);
|
|
409
|
-
});
|
|
410
|
-
it("handles multiple headers with same name", () => {
|
|
411
|
-
const result = phpCurl.generate({
|
|
412
|
-
url: "https://example.com",
|
|
413
|
-
headers: [
|
|
414
|
-
{ name: "X-Custom", value: "value1" },
|
|
415
|
-
{ name: "X-Custom", value: "value2" }
|
|
416
|
-
]
|
|
417
|
-
});
|
|
418
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
419
|
-
|
|
420
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Custom: value1', 'X-Custom: value2']);
|
|
421
|
-
|
|
422
|
-
curl_exec($ch);
|
|
423
|
-
|
|
424
|
-
curl_close($ch);`);
|
|
425
|
-
});
|
|
426
|
-
it("handles headers with empty values", () => {
|
|
427
|
-
const result = phpCurl.generate({
|
|
428
|
-
url: "https://example.com",
|
|
429
|
-
headers: [{ name: "X-Empty", value: "" }]
|
|
430
|
-
});
|
|
431
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
432
|
-
|
|
433
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Empty: ']);
|
|
434
|
-
|
|
435
|
-
curl_exec($ch);
|
|
436
|
-
|
|
437
|
-
curl_close($ch);`);
|
|
438
|
-
});
|
|
439
|
-
it("handles multipart form data with empty file names", () => {
|
|
440
|
-
const result = phpCurl.generate({
|
|
441
|
-
url: "https://example.com",
|
|
442
|
-
method: "POST",
|
|
443
|
-
postData: {
|
|
444
|
-
mimeType: "multipart/form-data",
|
|
445
|
-
params: [
|
|
446
|
-
{
|
|
447
|
-
name: "file",
|
|
448
|
-
fileName: ""
|
|
449
|
-
}
|
|
450
|
-
]
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
454
|
-
|
|
455
|
-
curl_setopt($ch, CURLOPT_POST, true);
|
|
456
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
|
|
457
|
-
curl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => '@']);
|
|
458
|
-
|
|
459
|
-
curl_exec($ch);
|
|
460
|
-
|
|
461
|
-
curl_close($ch);`);
|
|
462
|
-
});
|
|
463
|
-
it("handles JSON body with special characters using PHP array", () => {
|
|
464
|
-
const result = phpCurl.generate({
|
|
465
|
-
url: "https://example.com",
|
|
466
|
-
method: "POST",
|
|
467
|
-
headers: [
|
|
468
|
-
{
|
|
469
|
-
name: "Content-Type",
|
|
470
|
-
value: "application/json"
|
|
471
|
-
}
|
|
472
|
-
],
|
|
473
|
-
postData: {
|
|
474
|
-
mimeType: "application/json",
|
|
475
|
-
text: JSON.stringify({
|
|
476
|
-
key: '"quotes" and \\backslashes\\',
|
|
477
|
-
nested: {
|
|
478
|
-
array: ["item1", null, void 0]
|
|
479
|
-
}
|
|
480
|
-
})
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
484
|
-
|
|
485
|
-
curl_setopt($ch, CURLOPT_POST, true);
|
|
486
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
|
487
|
-
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
|
488
|
-
'key' => '"quotes" and \\backslashes\\',
|
|
489
|
-
'nested' => [
|
|
490
|
-
'array' => [
|
|
491
|
-
'item1',
|
|
492
|
-
null,
|
|
493
|
-
null
|
|
494
|
-
]
|
|
495
|
-
]
|
|
496
|
-
]));
|
|
497
|
-
|
|
498
|
-
curl_exec($ch);
|
|
499
|
-
|
|
500
|
-
curl_close($ch);`);
|
|
501
|
-
});
|
|
502
|
-
it("handles cookies with special characters", () => {
|
|
503
|
-
const result = phpCurl.generate({
|
|
504
|
-
url: "https://example.com",
|
|
505
|
-
cookies: [
|
|
506
|
-
{
|
|
507
|
-
name: "special;cookie",
|
|
508
|
-
value: "value with spaces"
|
|
509
|
-
}
|
|
510
|
-
]
|
|
511
|
-
});
|
|
512
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
513
|
-
|
|
514
|
-
curl_setopt($ch, CURLOPT_COOKIE, 'special%3Bcookie=value%20with%20spaces');
|
|
515
|
-
|
|
516
|
-
curl_exec($ch);
|
|
517
|
-
|
|
518
|
-
curl_close($ch);`);
|
|
519
|
-
});
|
|
520
|
-
it("prettifies JSON body using PHP array", () => {
|
|
521
|
-
const result = phpCurl.generate({
|
|
522
|
-
url: "https://example.com",
|
|
523
|
-
method: "POST",
|
|
524
|
-
headers: [
|
|
525
|
-
{
|
|
526
|
-
name: "Content-Type",
|
|
527
|
-
value: "application/json"
|
|
528
|
-
}
|
|
529
|
-
],
|
|
530
|
-
postData: {
|
|
531
|
-
mimeType: "application/json",
|
|
532
|
-
text: JSON.stringify({
|
|
533
|
-
nested: {
|
|
534
|
-
array: [1, 2, 3],
|
|
535
|
-
object: { foo: "bar" }
|
|
536
|
-
},
|
|
537
|
-
simple: "value"
|
|
538
|
-
})
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
expect(result).toBe(`$ch = curl_init("https://example.com");
|
|
542
|
-
|
|
543
|
-
curl_setopt($ch, CURLOPT_POST, true);
|
|
544
|
-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
|
545
|
-
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
|
546
|
-
'nested' => [
|
|
547
|
-
'array' => [
|
|
548
|
-
1,
|
|
549
|
-
2,
|
|
550
|
-
3
|
|
551
|
-
],
|
|
552
|
-
'object' => [
|
|
553
|
-
'foo' => 'bar'
|
|
554
|
-
]
|
|
555
|
-
],
|
|
556
|
-
'simple' => 'value'
|
|
557
|
-
]));
|
|
558
|
-
|
|
559
|
-
curl_exec($ch);
|
|
560
|
-
|
|
561
|
-
curl_close($ch);`);
|
|
562
|
-
});
|
|
563
|
-
});
|
|
564
|
-
//# sourceMappingURL=curl.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/plugins/php/curl/curl.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { phpCurl } from './curl'\n\ndescribe('phpCurl', () => {\n it('returns a basic request', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('returns a POST request', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n method: 'post',\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_POST, true);\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('has headers', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n headers: [\n {\n name: 'Content-Type',\n value: 'application/json',\n },\n ],\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it(\"doesn't add empty headers\", () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n headers: [],\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('has JSON body with PHP array', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n method: 'POST',\n headers: [\n {\n name: 'Content-Type',\n value: 'application/json',\n },\n ],\n postData: {\n mimeType: 'application/json',\n text: JSON.stringify({\n hello: 'world',\n }),\n },\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([\n 'hello' => 'world'\n]));\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('has query string', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n queryString: [\n {\n name: 'foo',\n value: 'bar',\n },\n {\n name: 'bar',\n value: 'foo',\n },\n ],\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com?foo=bar&bar=foo\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('has cookies', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n cookies: [\n {\n name: 'foo',\n value: 'bar',\n },\n {\n name: 'bar',\n value: 'foo',\n },\n ],\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_COOKIE, 'foo=bar; bar=foo');\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it(\"doesn't add empty cookies\", () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n cookies: [],\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('adds basic auth credentials', () => {\n const result = phpCurl.generate(\n {\n url: 'https://example.com',\n },\n {\n auth: {\n username: 'user',\n password: 'pass',\n },\n },\n )\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_USERPWD, 'user:pass');\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('omits auth when not provided', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('omits auth when username is missing', () => {\n const result = phpCurl.generate(\n {\n url: 'https://example.com',\n },\n {\n auth: {\n username: '',\n password: 'pass',\n },\n },\n )\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('omits auth when password is missing', () => {\n const result = phpCurl.generate(\n {\n url: 'https://example.com',\n },\n {\n auth: {\n username: 'user',\n password: '',\n },\n },\n )\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles special characters in auth credentials', () => {\n const result = phpCurl.generate(\n {\n url: 'https://example.com',\n },\n {\n auth: {\n username: 'user@example.com',\n password: 'pass:word!',\n },\n },\n )\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_USERPWD, 'user@example.com:pass:word!');\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles undefined auth object', () => {\n const result = phpCurl.generate(\n {\n url: 'https://example.com',\n },\n {\n auth: undefined,\n },\n )\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles multipart form data with files', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n method: 'POST',\n postData: {\n mimeType: 'multipart/form-data',\n params: [\n {\n name: 'file',\n fileName: 'test.txt',\n },\n {\n name: 'field',\n value: 'value',\n },\n ],\n },\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => '@test.txt', 'field' => 'value']);\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles multipart form data with JSON payload', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n method: 'POST',\n headers: [\n {\n name: 'Content-Type',\n value: 'multipart/form-data',\n },\n ],\n postData: {\n mimeType: 'multipart/form-data',\n text: JSON.stringify({\n foo: 'bar',\n }),\n },\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([\n 'foo' => 'bar'\n]));\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles url-encoded form data with special characters', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n method: 'POST',\n postData: {\n mimeType: 'application/x-www-form-urlencoded',\n params: [\n {\n name: 'special chars!@#',\n value: 'value',\n },\n ],\n },\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, 'special%20chars!%40%23=value');\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles binary data flag', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n method: 'POST',\n postData: {\n mimeType: 'application/octet-stream',\n text: 'binary content',\n },\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/octet-stream']);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, 'binary content');\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles compressed response', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n headers: [\n {\n name: 'Accept-Encoding',\n value: 'gzip, deflate',\n },\n ],\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept-Encoding: gzip, deflate']);\ncurl_setopt($ch, CURLOPT_ENCODING, '');\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles special characters in URL', () => {\n const result = phpCurl.generate({\n url: 'https://example.com/path with spaces/[brackets]',\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com/path with spaces/[brackets]\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles special characters in query parameters', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n queryString: [\n {\n name: 'q',\n value: 'hello world & more',\n },\n {\n name: 'special',\n value: '!@#$%^&*()',\n },\n ],\n })\n\n expect(\n result,\n ).toBe(`$ch = curl_init(\"https://example.com?q=hello%20world%20%26%20more&special=!%40%23%24%25%5E%26*()\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles empty URL', () => {\n const result = phpCurl.generate({\n url: '',\n })\n\n expect(result).toBe(`$ch = curl_init(\"\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles extremely long URLs', () => {\n const result = phpCurl.generate({\n url: 'https://example.com/' + 'a'.repeat(2000),\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com/${'a'.repeat(2000)}\");\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles multiple headers with same name', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n headers: [\n { name: 'X-Custom', value: 'value1' },\n { name: 'X-Custom', value: 'value2' },\n ],\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Custom: value1', 'X-Custom: value2']);\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles headers with empty values', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n headers: [{ name: 'X-Empty', value: '' }],\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Empty: ']);\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles multipart form data with empty file names', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n method: 'POST',\n postData: {\n mimeType: 'multipart/form-data',\n params: [\n {\n name: 'file',\n fileName: '',\n },\n ],\n },\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => '@']);\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles JSON body with special characters using PHP array', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n method: 'POST',\n headers: [\n {\n name: 'Content-Type',\n value: 'application/json',\n },\n ],\n postData: {\n mimeType: 'application/json',\n text: JSON.stringify({\n key: '\"quotes\" and \\\\backslashes\\\\',\n nested: {\n array: ['item1', null, undefined],\n },\n }),\n },\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([\n 'key' => '\"quotes\" and \\\\backslashes\\\\',\n 'nested' => [\n 'array' => [\n 'item1',\n null,\n null\n ]\n ]\n]));\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('handles cookies with special characters', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n cookies: [\n {\n name: 'special;cookie',\n value: 'value with spaces',\n },\n ],\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_COOKIE, 'special%3Bcookie=value%20with%20spaces');\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n\n it('prettifies JSON body using PHP array', () => {\n const result = phpCurl.generate({\n url: 'https://example.com',\n method: 'POST',\n headers: [\n {\n name: 'Content-Type',\n value: 'application/json',\n },\n ],\n postData: {\n mimeType: 'application/json',\n text: JSON.stringify({\n nested: {\n array: [1, 2, 3],\n object: { foo: 'bar' },\n },\n simple: 'value',\n }),\n },\n })\n\n expect(result).toBe(`$ch = curl_init(\"https://example.com\");\n\ncurl_setopt($ch, CURLOPT_POST, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([\n 'nested' => [\n 'array' => [\n 1,\n 2,\n 3\n ],\n 'object' => [\n 'foo' => 'bar'\n ]\n ],\n 'simple' => 'value'\n]));\n\ncurl_exec($ch);\n\ncurl_close($ch);`)\n })\n})\n"],
|
|
5
|
-
"m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