@scalar/snippetz 0.2.20 → 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/httpsnippet-lite/esm/targets/c/libcurl/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js +37 -8
- package/dist/httpsnippet-lite/esm/targets/c/libcurl/client.js.map +2 -2
- package/dist/httpsnippet-lite/esm/targets/go/native/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/go/native/client.js +76 -30
- package/dist/httpsnippet-lite/esm/targets/go/native/client.js.map +2 -2
- package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js +25 -9
- package/dist/httpsnippet-lite/esm/targets/java/okhttp/client.js.map +2 -2
- package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js +25 -9
- package/dist/httpsnippet-lite/esm/targets/kotlin/okhttp/client.js.map +2 -2
- package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.d.ts.map +1 -1
- package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js +11 -0
- package/dist/httpsnippet-lite/esm/targets/shell/httpie/client.js.map +2 -2
- package/dist/plugins/js/axios/index.d.ts +1 -1
- package/dist/plugins/js/axios/index.d.ts.map +1 -1
- package/dist/plugins/js/axios/index.js +4 -1
- package/dist/plugins/js/axios/index.js.map +2 -2
- package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/js/fetch/fetch.js +30 -9
- package/dist/plugins/js/fetch/fetch.js.map +2 -2
- package/dist/plugins/js/fetch/index.d.ts +1 -1
- package/dist/plugins/js/fetch/index.d.ts.map +1 -1
- package/dist/plugins/js/fetch/index.js +4 -1
- package/dist/plugins/js/fetch/index.js.map +2 -2
- package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/js/ofetch/ofetch.js +1 -10
- package/dist/plugins/js/ofetch/ofetch.js.map +2 -2
- package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/node/fetch/fetch.js +37 -9
- package/dist/plugins/node/fetch/fetch.js.map +2 -2
- package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/node/ofetch/ofetch.js +1 -10
- package/dist/plugins/node/ofetch/ofetch.js.map +2 -2
- package/dist/plugins/node/undici/undici.d.ts.map +1 -1
- package/dist/plugins/node/undici/undici.js +4 -6
- package/dist/plugins/node/undici/undici.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 -92
- package/dist/plugins/python/requests/requests.js.map +2 -2
- 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/dist/utils/create-search-params.d.ts +4 -0
- package/dist/utils/create-search-params.d.ts.map +1 -0
- package/dist/utils/create-search-params.js +11 -0
- package/dist/utils/create-search-params.js.map +7 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +2 -2
- package/dist/utils/objectToString.d.ts +8 -0
- package/dist/utils/objectToString.d.ts.map +1 -1
- package/dist/utils/objectToString.js +20 -15
- package/dist/utils/objectToString.js.map +2 -2
- package/package.json +10 -5
- package/dist/plugins/c/libcurl/libcurl.test.js +0 -200
- 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 -367
- 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/js/fetch/fetch.test.js +0 -111
- package/dist/plugins/js/fetch/fetch.test.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.test.js +0 -123
- package/dist/plugins/js/ofetch/ofetch.test.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.test.js +0 -111
- package/dist/plugins/node/fetch/fetch.test.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.test.js +0 -123
- 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 -390
- 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/arrayToObject.d.ts +0 -8
- package/dist/utils/arrayToObject.d.ts.map +0 -1
- package/dist/utils/arrayToObject.js +0 -10
- package/dist/utils/arrayToObject.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.test.js +0 -106
- package/dist/utils/convertWithHttpSnippetLite.test.js.map +0 -7
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { goNative } from "./native.js";
|
|
3
|
-
describe("goNative", () => {
|
|
4
|
-
it("returns a basic request", () => {
|
|
5
|
-
const result = goNative.generate({
|
|
6
|
-
url: "https://example.com"
|
|
7
|
-
});
|
|
8
|
-
expect(result).toBe(
|
|
9
|
-
`package main
|
|
10
|
-
|
|
11
|
-
import (
|
|
12
|
-
"fmt"
|
|
13
|
-
"net/http"
|
|
14
|
-
"io"
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
func main() {
|
|
18
|
-
|
|
19
|
-
url := "https://example.com"
|
|
20
|
-
|
|
21
|
-
req, _ := http.NewRequest("GET", url, nil)
|
|
22
|
-
|
|
23
|
-
res, _ := http.DefaultClient.Do(req)
|
|
24
|
-
|
|
25
|
-
defer res.Body.Close()
|
|
26
|
-
body, _ := io.ReadAll(res.Body)
|
|
27
|
-
|
|
28
|
-
fmt.Println(res)
|
|
29
|
-
fmt.Println(string(body))
|
|
30
|
-
|
|
31
|
-
}`
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
it("returns a POST request", () => {
|
|
35
|
-
const result = goNative.generate({
|
|
36
|
-
url: "https://example.com",
|
|
37
|
-
method: "post"
|
|
38
|
-
});
|
|
39
|
-
expect(result).toBe(
|
|
40
|
-
`package main
|
|
41
|
-
|
|
42
|
-
import (
|
|
43
|
-
"fmt"
|
|
44
|
-
"net/http"
|
|
45
|
-
"io"
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
func main() {
|
|
49
|
-
|
|
50
|
-
url := "https://example.com"
|
|
51
|
-
|
|
52
|
-
req, _ := http.NewRequest("POST", url, nil)
|
|
53
|
-
|
|
54
|
-
res, _ := http.DefaultClient.Do(req)
|
|
55
|
-
|
|
56
|
-
defer res.Body.Close()
|
|
57
|
-
body, _ := io.ReadAll(res.Body)
|
|
58
|
-
|
|
59
|
-
fmt.Println(res)
|
|
60
|
-
fmt.Println(string(body))
|
|
61
|
-
|
|
62
|
-
}`
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
it("has headers", () => {
|
|
66
|
-
const result = goNative.generate({
|
|
67
|
-
url: "https://example.com",
|
|
68
|
-
headers: [
|
|
69
|
-
{
|
|
70
|
-
name: "Content-Type",
|
|
71
|
-
value: "application/json"
|
|
72
|
-
}
|
|
73
|
-
]
|
|
74
|
-
});
|
|
75
|
-
expect(result).toBe(
|
|
76
|
-
`package main
|
|
77
|
-
|
|
78
|
-
import (
|
|
79
|
-
"fmt"
|
|
80
|
-
"net/http"
|
|
81
|
-
"io"
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
func main() {
|
|
85
|
-
|
|
86
|
-
url := "https://example.com"
|
|
87
|
-
|
|
88
|
-
req, _ := http.NewRequest("GET", url, nil)
|
|
89
|
-
|
|
90
|
-
req.Header.Add("Content-Type", "application/json")
|
|
91
|
-
|
|
92
|
-
res, _ := http.DefaultClient.Do(req)
|
|
93
|
-
|
|
94
|
-
defer res.Body.Close()
|
|
95
|
-
body, _ := io.ReadAll(res.Body)
|
|
96
|
-
|
|
97
|
-
fmt.Println(res)
|
|
98
|
-
fmt.Println(string(body))
|
|
99
|
-
|
|
100
|
-
}`
|
|
101
|
-
);
|
|
102
|
-
});
|
|
103
|
-
it.skip("handles multipart form data with files", () => {
|
|
104
|
-
const result = goNative.generate({
|
|
105
|
-
url: "https://example.com",
|
|
106
|
-
method: "POST",
|
|
107
|
-
postData: {
|
|
108
|
-
mimeType: "multipart/form-data",
|
|
109
|
-
params: [
|
|
110
|
-
{
|
|
111
|
-
name: "file",
|
|
112
|
-
fileName: "test.txt"
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: "field",
|
|
116
|
-
value: "value"
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
expect(result).toBe(
|
|
122
|
-
`package main
|
|
123
|
-
|
|
124
|
-
import (
|
|
125
|
-
"fmt"
|
|
126
|
-
"net/http"
|
|
127
|
-
"io"
|
|
128
|
-
"bytes"
|
|
129
|
-
"mime/multipart"
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
func main() {
|
|
133
|
-
|
|
134
|
-
url := "https://example.com"
|
|
135
|
-
|
|
136
|
-
body := &bytes.Buffer{}
|
|
137
|
-
writer := multipart.NewWriter(body)
|
|
138
|
-
|
|
139
|
-
// Add file field
|
|
140
|
-
writer.WriteField("file", "test.txt")
|
|
141
|
-
// Add form field
|
|
142
|
-
writer.WriteField("field", "value")
|
|
143
|
-
writer.Close()
|
|
144
|
-
|
|
145
|
-
req, _ := http.NewRequest("POST", url, body)
|
|
146
|
-
req.Header.Set("Content-Type", writer.FormDataContentType())
|
|
147
|
-
|
|
148
|
-
res, _ := http.DefaultClient.Do(req)
|
|
149
|
-
|
|
150
|
-
defer res.Body.Close()
|
|
151
|
-
responseBody, _ := io.ReadAll(res.Body)
|
|
152
|
-
|
|
153
|
-
fmt.Println(res)
|
|
154
|
-
fmt.Println(string(responseBody))
|
|
155
|
-
}`
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
it.skip("handles url-encoded form data with special characters", () => {
|
|
159
|
-
const result = goNative.generate({
|
|
160
|
-
url: "https://example.com",
|
|
161
|
-
method: "POST",
|
|
162
|
-
postData: {
|
|
163
|
-
mimeType: "application/x-www-form-urlencoded",
|
|
164
|
-
params: [
|
|
165
|
-
{
|
|
166
|
-
name: "special chars!@#",
|
|
167
|
-
value: "value"
|
|
168
|
-
}
|
|
169
|
-
]
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
expect(result).toBe(
|
|
173
|
-
`package main
|
|
174
|
-
|
|
175
|
-
import (
|
|
176
|
-
"fmt"
|
|
177
|
-
"net/http"
|
|
178
|
-
"io"
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
func main() {
|
|
182
|
-
|
|
183
|
-
url := "https://example.com"
|
|
184
|
-
|
|
185
|
-
req, _ := http.NewRequest("POST", url, nil)
|
|
186
|
-
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
187
|
-
|
|
188
|
-
res, _ := http.DefaultClient.Do(req)
|
|
189
|
-
|
|
190
|
-
defer res.Body.Close()
|
|
191
|
-
body, _ := io.ReadAll(res.Body)
|
|
192
|
-
|
|
193
|
-
fmt.Println(res)
|
|
194
|
-
fmt.Println(string(body))
|
|
195
|
-
|
|
196
|
-
}`
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
it("handles binary data", () => {
|
|
200
|
-
const result = goNative.generate({
|
|
201
|
-
url: "https://example.com",
|
|
202
|
-
method: "POST",
|
|
203
|
-
postData: {
|
|
204
|
-
mimeType: "application/octet-stream",
|
|
205
|
-
text: "binary content"
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
expect(result).toBe(
|
|
209
|
-
`package main
|
|
210
|
-
|
|
211
|
-
import (
|
|
212
|
-
"fmt"
|
|
213
|
-
"strings"
|
|
214
|
-
"net/http"
|
|
215
|
-
"io"
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
func main() {
|
|
219
|
-
|
|
220
|
-
url := "https://example.com"
|
|
221
|
-
|
|
222
|
-
payload := strings.NewReader("binary content")
|
|
223
|
-
|
|
224
|
-
req, _ := http.NewRequest("POST", url, payload)
|
|
225
|
-
|
|
226
|
-
res, _ := http.DefaultClient.Do(req)
|
|
227
|
-
|
|
228
|
-
defer res.Body.Close()
|
|
229
|
-
body, _ := io.ReadAll(res.Body)
|
|
230
|
-
|
|
231
|
-
fmt.Println(res)
|
|
232
|
-
fmt.Println(string(body))
|
|
233
|
-
|
|
234
|
-
}`
|
|
235
|
-
);
|
|
236
|
-
});
|
|
237
|
-
it("handles special characters in URL", () => {
|
|
238
|
-
const result = goNative.generate({
|
|
239
|
-
url: "https://example.com/path with spaces/[brackets]"
|
|
240
|
-
});
|
|
241
|
-
expect(result).toBe(
|
|
242
|
-
`package main
|
|
243
|
-
|
|
244
|
-
import (
|
|
245
|
-
"fmt"
|
|
246
|
-
"net/http"
|
|
247
|
-
"io"
|
|
248
|
-
)
|
|
249
|
-
|
|
250
|
-
func main() {
|
|
251
|
-
|
|
252
|
-
url := "https://example.com/path%20with%20spaces/[brackets]"
|
|
253
|
-
|
|
254
|
-
req, _ := http.NewRequest("GET", url, nil)
|
|
255
|
-
|
|
256
|
-
res, _ := http.DefaultClient.Do(req)
|
|
257
|
-
|
|
258
|
-
defer res.Body.Close()
|
|
259
|
-
body, _ := io.ReadAll(res.Body)
|
|
260
|
-
|
|
261
|
-
fmt.Println(res)
|
|
262
|
-
fmt.Println(string(body))
|
|
263
|
-
|
|
264
|
-
}`
|
|
265
|
-
);
|
|
266
|
-
});
|
|
267
|
-
it("handles multiple headers with same name", () => {
|
|
268
|
-
const result = goNative.generate({
|
|
269
|
-
url: "https://example.com",
|
|
270
|
-
headers: [
|
|
271
|
-
{ name: "X-Custom", value: "value1" },
|
|
272
|
-
{ name: "X-Custom", value: "value2" }
|
|
273
|
-
]
|
|
274
|
-
});
|
|
275
|
-
expect(result).toBe(
|
|
276
|
-
`package main
|
|
277
|
-
|
|
278
|
-
import (
|
|
279
|
-
"fmt"
|
|
280
|
-
"net/http"
|
|
281
|
-
"io"
|
|
282
|
-
)
|
|
283
|
-
|
|
284
|
-
func main() {
|
|
285
|
-
|
|
286
|
-
url := "https://example.com"
|
|
287
|
-
|
|
288
|
-
req, _ := http.NewRequest("GET", url, nil)
|
|
289
|
-
|
|
290
|
-
req.Header.Add("X-Custom", "value2")
|
|
291
|
-
|
|
292
|
-
res, _ := http.DefaultClient.Do(req)
|
|
293
|
-
|
|
294
|
-
defer res.Body.Close()
|
|
295
|
-
body, _ := io.ReadAll(res.Body)
|
|
296
|
-
|
|
297
|
-
fmt.Println(res)
|
|
298
|
-
fmt.Println(string(body))
|
|
299
|
-
|
|
300
|
-
}`
|
|
301
|
-
);
|
|
302
|
-
});
|
|
303
|
-
it("handles headers with empty values", () => {
|
|
304
|
-
const result = goNative.generate({
|
|
305
|
-
url: "https://example.com",
|
|
306
|
-
headers: [{ name: "X-Empty", value: "" }]
|
|
307
|
-
});
|
|
308
|
-
expect(result).toBe(
|
|
309
|
-
`package main
|
|
310
|
-
|
|
311
|
-
import (
|
|
312
|
-
"fmt"
|
|
313
|
-
"net/http"
|
|
314
|
-
"io"
|
|
315
|
-
)
|
|
316
|
-
|
|
317
|
-
func main() {
|
|
318
|
-
|
|
319
|
-
url := "https://example.com"
|
|
320
|
-
|
|
321
|
-
req, _ := http.NewRequest("GET", url, nil)
|
|
322
|
-
|
|
323
|
-
req.Header.Add("X-Empty", "")
|
|
324
|
-
|
|
325
|
-
res, _ := http.DefaultClient.Do(req)
|
|
326
|
-
|
|
327
|
-
defer res.Body.Close()
|
|
328
|
-
body, _ := io.ReadAll(res.Body)
|
|
329
|
-
|
|
330
|
-
fmt.Println(res)
|
|
331
|
-
fmt.Println(string(body))
|
|
332
|
-
|
|
333
|
-
}`
|
|
334
|
-
);
|
|
335
|
-
});
|
|
336
|
-
it("handles query string parameters", () => {
|
|
337
|
-
const result = goNative.generate({
|
|
338
|
-
url: "https://example.com/api?param1=value1¶m2=special value¶m3=123"
|
|
339
|
-
});
|
|
340
|
-
expect(result).toBe(
|
|
341
|
-
`package main
|
|
342
|
-
|
|
343
|
-
import (
|
|
344
|
-
"fmt"
|
|
345
|
-
"net/http"
|
|
346
|
-
"io"
|
|
347
|
-
)
|
|
348
|
-
|
|
349
|
-
func main() {
|
|
350
|
-
|
|
351
|
-
url := "https://example.com/api?param1=value1¶m2=special%20value¶m3=123"
|
|
352
|
-
|
|
353
|
-
req, _ := http.NewRequest("GET", url, nil)
|
|
354
|
-
|
|
355
|
-
res, _ := http.DefaultClient.Do(req)
|
|
356
|
-
|
|
357
|
-
defer res.Body.Close()
|
|
358
|
-
body, _ := io.ReadAll(res.Body)
|
|
359
|
-
|
|
360
|
-
fmt.Println(res)
|
|
361
|
-
fmt.Println(string(body))
|
|
362
|
-
|
|
363
|
-
}`
|
|
364
|
-
);
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
//# sourceMappingURL=native.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/plugins/go/native/native.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { goNative } from './native'\n\ndescribe('goNative', () => {\n it('returns a basic request', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('returns a POST request', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n method: 'post',\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"POST\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('has headers', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n headers: [\n {\n name: 'Content-Type',\n value: 'application/json',\n },\n ],\n })\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"Content-Type\", \"application/json\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it.skip('handles multipart form data with files', () => {\n const result = goNative.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(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n\t\"bytes\"\n\t\"mime/multipart\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com\"\n\n\tbody := &bytes.Buffer{}\n\twriter := multipart.NewWriter(body)\n\n\t// Add file field\n\twriter.WriteField(\"file\", \"test.txt\")\n\t// Add form field\n\twriter.WriteField(\"field\", \"value\")\n\twriter.Close()\n\n\treq, _ := http.NewRequest(\"POST\", url, body)\n\treq.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tresponseBody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(responseBody))\n}`,\n )\n })\n\n it.skip('handles url-encoded form data with special characters', () => {\n const result = goNative.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(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"POST\", url, nil)\n\treq.Header.Add(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles binary data', () => {\n const result = goNative.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(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com\"\n\n\tpayload := strings.NewReader(\"binary content\")\n\n\treq, _ := http.NewRequest(\"POST\", url, payload)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles special characters in URL', () => {\n const result = goNative.generate({\n url: 'https://example.com/path with spaces/[brackets]',\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com/path%20with%20spaces/[brackets]\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles multiple headers with same name', () => {\n const result = goNative.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(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"X-Custom\", \"value2\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles headers with empty values', () => {\n const result = goNative.generate({\n url: 'https://example.com',\n headers: [{ name: 'X-Empty', value: '' }],\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\treq.Header.Add(\"X-Empty\", \"\")\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n\tfmt.Println(res)\n\tfmt.Println(string(body))\n\n}`,\n )\n })\n\n it('handles query string parameters', () => {\n const result = goNative.generate({\n url: 'https://example.com/api?param1=value1¶m2=special value¶m3=123',\n })\n\n expect(result).toBe(\n `package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"io\"\n)\n\nfunc main() {\n\n\turl := \"https://example.com/api?param1=value1¶m2=special%20value¶m3=123\"\n\n\treq, _ := http.NewRequest(\"GET\", url, nil)\n\n\tres, _ := http.DefaultClient.Do(req)\n\n\tdefer res.Body.Close()\n\tbody, _ := io.ReadAll(res.Body)\n\n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AAE;AAAA,MACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAuBF;AAAA,EACF,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { httpHttp11 } from "./http11.js";
|
|
3
|
-
describe("httpHttp11", () => {
|
|
4
|
-
it("returns a basic request", () => {
|
|
5
|
-
const result = httpHttp11.generate({
|
|
6
|
-
url: "https://example.com"
|
|
7
|
-
});
|
|
8
|
-
expect(result).toBe("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n");
|
|
9
|
-
});
|
|
10
|
-
it("returns a POST request", () => {
|
|
11
|
-
const result = httpHttp11.generate({
|
|
12
|
-
url: "https://example.com",
|
|
13
|
-
method: "post"
|
|
14
|
-
});
|
|
15
|
-
expect(result).toBe("POST / HTTP/1.1\r\nHost: example.com\r\n\r\n");
|
|
16
|
-
});
|
|
17
|
-
it("has headers", () => {
|
|
18
|
-
const result = httpHttp11.generate({
|
|
19
|
-
url: "https://example.com",
|
|
20
|
-
headers: [
|
|
21
|
-
{
|
|
22
|
-
name: "Content-Type",
|
|
23
|
-
value: "application/json"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
});
|
|
27
|
-
expect(result).toBe("GET / HTTP/1.1\r\nHost: example.com\r\nContent-Type: application/json\r\n\r\n");
|
|
28
|
-
});
|
|
29
|
-
it("it doesn\u2019t add the JSON header twice", () => {
|
|
30
|
-
const result = httpHttp11.generate({
|
|
31
|
-
url: "https://example.com",
|
|
32
|
-
method: "post",
|
|
33
|
-
headers: [
|
|
34
|
-
{
|
|
35
|
-
name: "Content-Type",
|
|
36
|
-
value: "application/json"
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
postData: {
|
|
40
|
-
mimeType: "application/json",
|
|
41
|
-
text: '{"foo": "bar"}'
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
expect(result).toBe(
|
|
45
|
-
'POST / HTTP/1.1\r\nHost: example.com\r\nContent-Type: application/json\r\n\r\n{"foo": "bar"}'
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
it("handles multipart form data with files", () => {
|
|
49
|
-
const result = httpHttp11.generate({
|
|
50
|
-
url: "https://example.com",
|
|
51
|
-
method: "POST",
|
|
52
|
-
postData: {
|
|
53
|
-
mimeType: "multipart/form-data",
|
|
54
|
-
params: [
|
|
55
|
-
{
|
|
56
|
-
name: "file",
|
|
57
|
-
fileName: "test.txt"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
name: "field",
|
|
61
|
-
value: "value"
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
expect(result).toMatch(
|
|
67
|
-
'POST / HTTP/1.1\r\nHost: example.com\r\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name="file"; filename="test.txt"\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name="field"\r\n\r\nvalue\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\r\n'
|
|
68
|
-
);
|
|
69
|
-
});
|
|
70
|
-
it("handles url-encoded form data with special characters", () => {
|
|
71
|
-
const result = httpHttp11.generate({
|
|
72
|
-
url: "https://example.com",
|
|
73
|
-
method: "POST",
|
|
74
|
-
postData: {
|
|
75
|
-
mimeType: "application/x-www-form-urlencoded",
|
|
76
|
-
params: [
|
|
77
|
-
{
|
|
78
|
-
name: "special chars!@#",
|
|
79
|
-
value: "value"
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
expect(result).toBe(
|
|
85
|
-
"POST / HTTP/1.1\r\nHost: example.com\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nspecial%20chars!%40%23=value"
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
it("handles binary data", () => {
|
|
89
|
-
const result = httpHttp11.generate({
|
|
90
|
-
url: "https://example.com",
|
|
91
|
-
method: "POST",
|
|
92
|
-
postData: {
|
|
93
|
-
mimeType: "application/octet-stream",
|
|
94
|
-
text: "binary content"
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
expect(result).toBe(
|
|
98
|
-
"POST / HTTP/1.1\r\nHost: example.com\r\nContent-Type: application/octet-stream\r\n\r\nbinary content"
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
it("handles special characters in URL", () => {
|
|
102
|
-
const result = httpHttp11.generate({
|
|
103
|
-
url: "https://example.com/path with spaces/[brackets]"
|
|
104
|
-
});
|
|
105
|
-
expect(result).toBe("GET /path%20with%20spaces/[brackets] HTTP/1.1\r\nHost: example.com\r\n\r\n");
|
|
106
|
-
});
|
|
107
|
-
it("handles multiple headers with same name", () => {
|
|
108
|
-
const result = httpHttp11.generate({
|
|
109
|
-
url: "https://example.com",
|
|
110
|
-
headers: [
|
|
111
|
-
{ name: "X-Custom", value: "value1" },
|
|
112
|
-
{ name: "X-Custom", value: "value2" }
|
|
113
|
-
]
|
|
114
|
-
});
|
|
115
|
-
expect(result).toBe(
|
|
116
|
-
"GET / HTTP/1.1\r\nHost: example.com\r\nX-Custom: value1, value2\r\n\r\n"
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
it("handles headers with empty values", () => {
|
|
120
|
-
const result = httpHttp11.generate({
|
|
121
|
-
url: "https://example.com",
|
|
122
|
-
headers: [{ name: "X-Empty", value: "" }]
|
|
123
|
-
});
|
|
124
|
-
expect(result).toBe("GET / HTTP/1.1\r\nHost: example.com\r\nX-Empty: \r\n\r\n");
|
|
125
|
-
});
|
|
126
|
-
it("handles query string parameters", () => {
|
|
127
|
-
const result = httpHttp11.generate({
|
|
128
|
-
url: "https://example.com/api?param1=value1¶m2=special value¶m3=123"
|
|
129
|
-
});
|
|
130
|
-
expect(result).toBe(
|
|
131
|
-
"GET /api?param1=value1¶m2=special%20value¶m3=123 HTTP/1.1\r\nHost: example.com\r\n\r\n"
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
it("handles invalid URL", () => {
|
|
135
|
-
const result = httpHttp11.generate({
|
|
136
|
-
url: "/foo"
|
|
137
|
-
});
|
|
138
|
-
expect(result).toBe("GET /foo HTTP/1.1\r\nHost: UNKNOWN_HOSTNAME\r\n\r\n");
|
|
139
|
-
});
|
|
140
|
-
it("handles empty URL", () => {
|
|
141
|
-
const result = httpHttp11.generate({
|
|
142
|
-
url: ""
|
|
143
|
-
});
|
|
144
|
-
expect(result).toBe("GET / HTTP/1.1\r\nHost: UNKNOWN_HOSTNAME\r\n\r\n");
|
|
145
|
-
});
|
|
146
|
-
it("handles extremely long URLs", () => {
|
|
147
|
-
const longUrl = "https://example.com/" + "a".repeat(2e3);
|
|
148
|
-
const result = httpHttp11.generate({
|
|
149
|
-
url: longUrl
|
|
150
|
-
});
|
|
151
|
-
expect(result).toBe(`GET /${"a".repeat(2e3)} HTTP/1.1\r
|
|
152
|
-
Host: example.com\r
|
|
153
|
-
\r
|
|
154
|
-
`);
|
|
155
|
-
});
|
|
156
|
-
it("handles special characters in query parameters", () => {
|
|
157
|
-
const result = httpHttp11.generate({
|
|
158
|
-
url: "https://example.com",
|
|
159
|
-
queryString: [
|
|
160
|
-
{
|
|
161
|
-
name: "q",
|
|
162
|
-
value: "hello world & more"
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: "special",
|
|
166
|
-
value: "!@#$%^&*()"
|
|
167
|
-
}
|
|
168
|
-
]
|
|
169
|
-
});
|
|
170
|
-
expect(result).toBe(
|
|
171
|
-
"GET /?q=hello%20world%20%26%20more&special=!%40%23%24%25%5E%26*() HTTP/1.1\r\nHost: example.com\r\n\r\n"
|
|
172
|
-
);
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
//# sourceMappingURL=http11.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/plugins/http/http11/http11.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { httpHttp11 } from './http11'\n\ndescribe('httpHttp11', () => {\n it('returns a basic request', () => {\n const result = httpHttp11.generate({\n url: 'https://example.com',\n })\n\n expect(result).toBe('GET / HTTP/1.1\\r\\n' + 'Host: example.com\\r\\n' + '\\r\\n')\n })\n\n it('returns a POST request', () => {\n const result = httpHttp11.generate({\n url: 'https://example.com',\n method: 'post',\n })\n\n expect(result).toBe('POST / HTTP/1.1\\r\\n' + 'Host: example.com\\r\\n' + '\\r\\n')\n })\n\n it('has headers', () => {\n const result = httpHttp11.generate({\n url: 'https://example.com',\n headers: [\n {\n name: 'Content-Type',\n value: 'application/json',\n },\n ],\n })\n expect(result).toBe('GET / HTTP/1.1\\r\\n' + 'Host: example.com\\r\\n' + 'Content-Type: application/json\\r\\n' + '\\r\\n')\n })\n\n it('it doesn\u2019t add the JSON header twice', () => {\n const result = httpHttp11.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: '{\"foo\": \"bar\"}',\n },\n })\n\n expect(result).toBe(\n 'POST / HTTP/1.1\\r\\n' +\n 'Host: example.com\\r\\n' +\n 'Content-Type: application/json\\r\\n' +\n '\\r\\n' +\n '{\"foo\": \"bar\"}',\n )\n })\n\n it('handles multipart form data with files', () => {\n const result = httpHttp11.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).toMatch(\n 'POST / HTTP/1.1\\r\\n' +\n 'Host: example.com\\r\\n' +\n 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\\r\\n' +\n '\\r\\n' +\n '------WebKitFormBoundary7MA4YWxkTrZu0gW\\r\\n' +\n 'Content-Disposition: form-data; name=\"file\"; filename=\"test.txt\"\\r\\n' +\n '\\r\\n' +\n '------WebKitFormBoundary7MA4YWxkTrZu0gW\\r\\n' +\n 'Content-Disposition: form-data; name=\"field\"\\r\\n' +\n '\\r\\n' +\n 'value\\r\\n' +\n '------WebKitFormBoundary7MA4YWxkTrZu0gW--\\r\\n',\n )\n })\n\n it('handles url-encoded form data with special characters', () => {\n const result = httpHttp11.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(\n 'POST / HTTP/1.1\\r\\n' +\n 'Host: example.com\\r\\n' +\n 'Content-Type: application/x-www-form-urlencoded\\r\\n' +\n '\\r\\n' +\n 'special%20chars!%40%23=value',\n )\n })\n\n it('handles binary data', () => {\n const result = httpHttp11.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(\n 'POST / HTTP/1.1\\r\\n' +\n 'Host: example.com\\r\\n' +\n 'Content-Type: application/octet-stream\\r\\n' +\n '\\r\\n' +\n 'binary content',\n )\n })\n\n it('handles special characters in URL', () => {\n const result = httpHttp11.generate({\n url: 'https://example.com/path with spaces/[brackets]',\n })\n\n expect(result).toBe('GET /path%20with%20spaces/[brackets] HTTP/1.1\\r\\n' + 'Host: example.com\\r\\n' + '\\r\\n')\n })\n\n it('handles multiple headers with same name', () => {\n const result = httpHttp11.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(\n 'GET / HTTP/1.1\\r\\n' +\n 'Host: example.com\\r\\n' +\n // RFC 7230 states a server must not generate multiple header fields with the same field name unless either the entire field value for that header field is defined as a comma-separated list, or the header field is a well-known exception.\n 'X-Custom: value1, value2\\r\\n' +\n '\\r\\n',\n )\n })\n\n it('handles headers with empty values', () => {\n const result = httpHttp11.generate({\n url: 'https://example.com',\n headers: [{ name: 'X-Empty', value: '' }],\n })\n\n expect(result).toBe('GET / HTTP/1.1\\r\\n' + 'Host: example.com\\r\\n' + 'X-Empty: \\r\\n' + '\\r\\n')\n })\n\n it('handles query string parameters', () => {\n const result = httpHttp11.generate({\n url: 'https://example.com/api?param1=value1¶m2=special value¶m3=123',\n })\n\n expect(result).toBe(\n 'GET /api?param1=value1¶m2=special%20value¶m3=123 HTTP/1.1\\r\\n' + 'Host: example.com\\r\\n' + '\\r\\n',\n )\n })\n\n it('handles invalid URL', () => {\n const result = httpHttp11.generate({\n url: '/foo',\n })\n\n expect(result).toBe('GET /foo HTTP/1.1\\r\\n' + 'Host: UNKNOWN_HOSTNAME\\r\\n' + '\\r\\n')\n })\n\n it('handles empty URL', () => {\n const result = httpHttp11.generate({\n url: '',\n })\n\n expect(result).toBe('GET / HTTP/1.1\\r\\n' + 'Host: UNKNOWN_HOSTNAME\\r\\n' + '\\r\\n')\n })\n\n it('handles extremely long URLs', () => {\n const longUrl = 'https://example.com/' + 'a'.repeat(2000)\n const result = httpHttp11.generate({\n url: longUrl,\n })\n\n expect(result).toBe(`GET /${'a'.repeat(2000)} HTTP/1.1\\r\\n` + 'Host: example.com\\r\\n' + '\\r\\n')\n })\n\n it('handles special characters in query parameters', () => {\n const result = httpHttp11.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(result).toBe(\n 'GET /?q=hello%20world%20%26%20more&special=!%40%23%24%25%5E%26*() HTTP/1.1\\r\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