@scalar/snippetz 0.7.4 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/index.js +168 -169
- package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
- package/dist/httpsnippet-lite/helpers/escape.js +69 -44
- package/dist/httpsnippet-lite/helpers/headers.js +17 -14
- package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
- package/dist/httpsnippet-lite/helpers/shell.js +13 -13
- package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
- package/dist/httpsnippet-lite/helpers/url.js +4 -8
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
- package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
- package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
- package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
- package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
- package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
- package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
- package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
- package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
- package/dist/httpsnippet-lite/targets/target.js +1 -1
- package/dist/index.js +2 -9
- package/dist/libs/http.js +68 -56
- package/dist/libs/javascript.js +77 -60
- package/dist/libs/php.js +59 -49
- package/dist/libs/rust.js +60 -33
- package/dist/libs/shell.js +14 -5
- package/dist/plugins/c/libcurl/index.js +1 -5
- package/dist/plugins/c/libcurl/libcurl.js +13 -13
- package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
- package/dist/plugins/clojure/clj_http/index.js +1 -5
- package/dist/plugins/csharp/httpclient/httpclient.js +206 -150
- package/dist/plugins/csharp/httpclient/index.js +1 -5
- package/dist/plugins/csharp/restsharp/index.js +1 -5
- package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
- package/dist/plugins/dart/http/http.js +95 -93
- package/dist/plugins/dart/http/index.js +1 -5
- package/dist/plugins/fsharp/httpclient/httpclient.js +169 -122
- package/dist/plugins/fsharp/httpclient/index.js +1 -5
- package/dist/plugins/go/native/index.js +1 -5
- package/dist/plugins/go/native/native.js +13 -13
- package/dist/plugins/http/http11/http11.d.ts.map +1 -1
- package/dist/plugins/http/http11/http11.js +104 -85
- package/dist/plugins/http/http11/index.js +1 -5
- package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
- package/dist/plugins/java/asynchttp/index.js +1 -5
- package/dist/plugins/java/nethttp/index.js +1 -5
- package/dist/plugins/java/nethttp/nethttp.js +13 -13
- package/dist/plugins/java/okhttp/index.js +1 -5
- package/dist/plugins/java/okhttp/okhttp.js +13 -13
- package/dist/plugins/java/unirest/index.js +1 -5
- package/dist/plugins/java/unirest/unirest.js +13 -13
- package/dist/plugins/js/axios/axios.js +13 -13
- package/dist/plugins/js/axios/index.js +1 -5
- package/dist/plugins/js/fetch/fetch.js +82 -68
- package/dist/plugins/js/fetch/index.js +1 -5
- package/dist/plugins/js/jquery/index.js +1 -5
- package/dist/plugins/js/jquery/jquery.js +13 -13
- package/dist/plugins/js/ofetch/index.js +1 -5
- package/dist/plugins/js/ofetch/ofetch.js +61 -48
- package/dist/plugins/js/xhr/index.js +1 -5
- package/dist/plugins/js/xhr/xhr.js +13 -13
- package/dist/plugins/kotlin/okhttp/index.js +1 -5
- package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
- package/dist/plugins/node/axios/axios.js +13 -13
- package/dist/plugins/node/axios/index.js +1 -5
- package/dist/plugins/node/fetch/fetch.js +86 -74
- package/dist/plugins/node/fetch/index.js +1 -5
- package/dist/plugins/node/ofetch/index.js +1 -5
- package/dist/plugins/node/ofetch/ofetch.js +61 -48
- package/dist/plugins/node/undici/index.js +1 -5
- package/dist/plugins/node/undici/undici.js +60 -47
- package/dist/plugins/objc/nsurlsession/index.js +1 -5
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
- package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
- package/dist/plugins/ocaml/cohttp/index.js +1 -5
- package/dist/plugins/php/curl/curl.js +143 -101
- package/dist/plugins/php/curl/index.js +1 -5
- package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -1
- package/dist/plugins/php/guzzle/guzzle.js +109 -83
- package/dist/plugins/php/guzzle/index.js +1 -5
- package/dist/plugins/powershell/restmethod/index.js +1 -5
- package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
- package/dist/plugins/powershell/webrequest/index.js +1 -5
- package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
- package/dist/plugins/python/httpx/async.js +17 -15
- package/dist/plugins/python/httpx/index.js +2 -7
- package/dist/plugins/python/httpx/sync.js +11 -12
- package/dist/plugins/python/python3/index.js +1 -5
- package/dist/plugins/python/python3/python3.js +13 -13
- package/dist/plugins/python/requests/index.js +1 -5
- package/dist/plugins/python/requests/requests.js +11 -12
- package/dist/plugins/python/requestsLike.d.ts.map +1 -1
- package/dist/plugins/python/requestsLike.js +145 -112
- package/dist/plugins/r/httr/httr.js +13 -13
- package/dist/plugins/r/httr/index.js +1 -5
- package/dist/plugins/ruby/native/index.js +1 -5
- package/dist/plugins/ruby/native/native.js +13 -13
- package/dist/plugins/rust/reqwest/index.js +1 -5
- package/dist/plugins/rust/reqwest/reqwest.js +126 -83
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
- package/dist/plugins/shell/curl/curl.js +129 -97
- package/dist/plugins/shell/curl/index.js +1 -5
- package/dist/plugins/shell/httpie/httpie.js +13 -13
- package/dist/plugins/shell/httpie/index.js +1 -5
- package/dist/plugins/shell/wget/index.js +1 -5
- package/dist/plugins/shell/wget/wget.js +13 -13
- package/dist/plugins/swift/nsurlsession/index.js +1 -5
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
- package/dist/snippetz.js +25 -28
- package/dist/utils/convertWithHttpSnippetLite.js +100 -96
- package/dist/utils/index.js +1 -5
- package/package.json +8 -12
- package/dist/clients/index.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/target.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/libs/http.js.map +0 -7
- package/dist/libs/javascript.js.map +0 -7
- package/dist/libs/php.js.map +0 -7
- package/dist/libs/rust.js.map +0 -7
- package/dist/libs/shell.js.map +0 -7
- package/dist/plugins/c/libcurl/index.js.map +0 -7
- package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
- package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
- package/dist/plugins/clojure/clj_http/index.js.map +0 -7
- package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/csharp/httpclient/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
- package/dist/plugins/dart/http/http.js.map +0 -7
- package/dist/plugins/dart/http/index.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
- package/dist/plugins/go/native/index.js.map +0 -7
- package/dist/plugins/go/native/native.js.map +0 -7
- package/dist/plugins/http/http11/http11.js.map +0 -7
- package/dist/plugins/http/http11/index.js.map +0 -7
- package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
- package/dist/plugins/java/asynchttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
- package/dist/plugins/java/okhttp/index.js.map +0 -7
- package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/java/unirest/index.js.map +0 -7
- package/dist/plugins/java/unirest/unirest.js.map +0 -7
- package/dist/plugins/js/axios/axios.js.map +0 -7
- package/dist/plugins/js/axios/index.js.map +0 -7
- package/dist/plugins/js/fetch/fetch.js.map +0 -7
- package/dist/plugins/js/fetch/index.js.map +0 -7
- package/dist/plugins/js/jquery/index.js.map +0 -7
- package/dist/plugins/js/jquery/jquery.js.map +0 -7
- package/dist/plugins/js/ofetch/index.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/js/xhr/index.js.map +0 -7
- package/dist/plugins/js/xhr/xhr.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/node/axios/axios.js.map +0 -7
- package/dist/plugins/node/axios/index.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.js.map +0 -7
- package/dist/plugins/node/fetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/node/undici/index.js.map +0 -7
- package/dist/plugins/node/undici/undici.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
- package/dist/plugins/php/curl/curl.js.map +0 -7
- package/dist/plugins/php/curl/index.js.map +0 -7
- package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
- package/dist/plugins/php/guzzle/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
- package/dist/plugins/powershell/webrequest/index.js.map +0 -7
- package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
- package/dist/plugins/python/httpx/async.js.map +0 -7
- package/dist/plugins/python/httpx/index.js.map +0 -7
- package/dist/plugins/python/httpx/sync.js.map +0 -7
- package/dist/plugins/python/python3/index.js.map +0 -7
- package/dist/plugins/python/python3/python3.js.map +0 -7
- package/dist/plugins/python/requests/index.js.map +0 -7
- package/dist/plugins/python/requests/requests.js.map +0 -7
- package/dist/plugins/python/requestsLike.js.map +0 -7
- package/dist/plugins/r/httr/httr.js.map +0 -7
- package/dist/plugins/r/httr/index.js.map +0 -7
- package/dist/plugins/ruby/native/index.js.map +0 -7
- package/dist/plugins/ruby/native/native.js.map +0 -7
- package/dist/plugins/rust/reqwest/index.js.map +0 -7
- package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
- package/dist/plugins/shell/curl/curl.js.map +0 -7
- package/dist/plugins/shell/curl/index.js.map +0 -7
- package/dist/plugins/shell/httpie/httpie.js.map +0 -7
- package/dist/plugins/shell/httpie/index.js.map +0 -7
- package/dist/plugins/shell/wget/index.js.map +0 -7
- package/dist/plugins/shell/wget/wget.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/snippetz.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
- package/dist/utils/index.js.map +0 -7
|
@@ -1,148 +1,195 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
/**
|
|
2
|
+
* F# HttpClient plugin for generating HTTP request code
|
|
3
|
+
*/
|
|
4
|
+
export const fsharpHttpclient = {
|
|
5
|
+
target: 'fsharp',
|
|
6
|
+
client: 'httpclient',
|
|
7
|
+
title: 'HttpClient',
|
|
8
|
+
generate: (request, _) => {
|
|
9
|
+
if (!request) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
const finalUrl = buildUrlWithQueryString(request.url, request.queryString);
|
|
13
|
+
let code = '';
|
|
14
|
+
// Initialize HttpRequestMessage
|
|
15
|
+
code += generateHttpRequestMessage(request.method, finalUrl);
|
|
16
|
+
// Add headers if present
|
|
17
|
+
if (request.headers && request.headers.length > 0) {
|
|
18
|
+
code += generateHeadersCode(request.headers);
|
|
19
|
+
}
|
|
20
|
+
// Add request body if present
|
|
21
|
+
if (request.postData) {
|
|
22
|
+
code += generatePostDataCode(request.postData);
|
|
23
|
+
}
|
|
24
|
+
// Configure client with cookies if present
|
|
25
|
+
if (request.cookies && request.cookies.length > 0 && request.url) {
|
|
26
|
+
code += generateCookiesCode(request.cookies, request.url);
|
|
27
|
+
code += 'let client = new HttpClient(handler)\n';
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
code += 'let client = new HttpClient()\n';
|
|
31
|
+
}
|
|
32
|
+
// Send the request
|
|
33
|
+
code += 'let! result = client.SendAsync(httpRequestMessage)\n';
|
|
34
|
+
return code;
|
|
35
|
+
},
|
|
27
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Builds a query string from an array of query parameters
|
|
39
|
+
*/
|
|
28
40
|
function buildQueryString(queryParams) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
if (!queryParams || queryParams.length === 0) {
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
const params = queryParams.map((param) => `${param.name}=${param.value}`);
|
|
45
|
+
return '?' + params.join('&');
|
|
34
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Combines base URL with query string if present
|
|
49
|
+
*/
|
|
35
50
|
function buildUrlWithQueryString(baseUrl, queryParams) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
if (!baseUrl) {
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
if (!queryParams || queryParams.length === 0) {
|
|
55
|
+
return baseUrl;
|
|
56
|
+
}
|
|
57
|
+
return baseUrl + buildQueryString(queryParams);
|
|
43
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Generates the HttpRequestMessage initialization code
|
|
61
|
+
*/
|
|
44
62
|
function generateHttpRequestMessage(method, url) {
|
|
45
|
-
|
|
63
|
+
return `let httpRequestMessage = new HttpRequestMessage(
|
|
46
64
|
HttpMethod("${method}"),
|
|
47
65
|
new Uri("${escapeString(url)}")
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
`;
|
|
66
|
+
)\n\n`;
|
|
51
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Generates code to add headers to the HttpRequestMessage
|
|
70
|
+
*/
|
|
52
71
|
function generateHeadersCode(headers) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return code;
|
|
72
|
+
let code = '';
|
|
73
|
+
for (const header of headers) {
|
|
74
|
+
code += `httpRequestMessage.Headers.Add("${escapeString(header.name ?? '')}", "${escapeString(header.value ?? '')}")\n`;
|
|
75
|
+
}
|
|
76
|
+
code += '\n';
|
|
77
|
+
return code;
|
|
60
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Generates code to configure cookies for the HttpClient
|
|
81
|
+
*/
|
|
61
82
|
function generateCookiesCode(cookies, url) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return code;
|
|
83
|
+
let code = 'let cookieContainer = CookieContainer()\n';
|
|
84
|
+
for (const cookie of cookies) {
|
|
85
|
+
code += `cookieContainer.Add(Uri("${escapeString(url)}"), Cookie("${escapeString(cookie.name ?? '')}", "${escapeString(cookie.value ?? '')}"))\n`;
|
|
86
|
+
}
|
|
87
|
+
code += 'use handler = new HttpClientHandler()\n';
|
|
88
|
+
code += 'handler.CookieContainer <- cookieContainer\n\n';
|
|
89
|
+
return code;
|
|
70
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Generates code to set the request content based on postData
|
|
93
|
+
*/
|
|
71
94
|
function generatePostDataCode(postData) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
if (!postData) {
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
let code = '';
|
|
99
|
+
switch (postData.mimeType) {
|
|
100
|
+
case 'multipart/form-data':
|
|
101
|
+
code += generateMultipartFormDataCode(postData);
|
|
102
|
+
break;
|
|
103
|
+
case 'application/x-www-form-urlencoded':
|
|
104
|
+
code += generateUrlEncodedFormDataCode(postData);
|
|
105
|
+
break;
|
|
106
|
+
case 'application/json':
|
|
107
|
+
code += generateJsonContentCode(postData);
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
code += generateGenericContentCode(postData, postData.mimeType);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
code += 'httpRequestMessage.Content <- content\n\n';
|
|
114
|
+
return code;
|
|
92
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Generates code for generic content types
|
|
118
|
+
*/
|
|
93
119
|
function generateGenericContentCode(postData, contentType) {
|
|
94
|
-
|
|
95
|
-
`;
|
|
96
|
-
|
|
97
|
-
`;
|
|
98
|
-
return code;
|
|
120
|
+
let code = `let content = new StringContent("${escapeString(postData.text ?? '')}", Encoding.UTF8, "${escapeString(contentType ?? '')}")\n`;
|
|
121
|
+
code += `content.Headers.ContentType <- MediaTypeHeaderValue("${escapeString(contentType ?? '')}")\n`;
|
|
122
|
+
return code;
|
|
99
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Generates code for multipart/form-data content
|
|
126
|
+
*/
|
|
100
127
|
function generateMultipartFormDataCode(postData) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
`;
|
|
108
|
-
|
|
109
|
-
`;
|
|
110
|
-
|
|
111
|
-
`;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
128
|
+
let code = 'let content = new MultipartFormDataContent()\n';
|
|
129
|
+
let fileIndex = 0;
|
|
130
|
+
let stringContentIndex = 0;
|
|
131
|
+
for (const param of postData.params) {
|
|
132
|
+
if (param.value === 'BINARY') {
|
|
133
|
+
const escapedFileName = escapeString(param.fileName ?? '');
|
|
134
|
+
code += `let fileStreamContent_${fileIndex} = new StreamContent(File.OpenRead("${escapedFileName}"))\n`;
|
|
135
|
+
if (param.contentType) {
|
|
136
|
+
code += `fileStreamContent_${fileIndex}.Headers.ContentType <- MediaTypeHeaderValue("${escapeString(param.contentType)}")\n`;
|
|
137
|
+
}
|
|
138
|
+
code += `content.Add(fileStreamContent_${fileIndex}, "${escapedFileName}", "${escapedFileName}")\n`;
|
|
139
|
+
fileIndex++;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
const escapedName = escapeString(param.name ?? '');
|
|
143
|
+
const escapedValue = escapeString(param.value ?? '');
|
|
144
|
+
if (param.contentType) {
|
|
145
|
+
code += `let stringContent_${stringContentIndex} = new StringContent("${escapedValue}")\n`;
|
|
146
|
+
code += `stringContent_${stringContentIndex}.Headers.ContentType <- MediaTypeHeaderValue("${escapeString(param.contentType)}")\n`;
|
|
147
|
+
code += `content.Add(stringContent_${stringContentIndex}, "${escapedName}")\n`;
|
|
148
|
+
stringContentIndex++;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
code += `content.Add(new StringContent("${escapedValue}"), "${escapedName}")\n`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
116
154
|
}
|
|
117
|
-
|
|
118
|
-
return code;
|
|
155
|
+
return code;
|
|
119
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Generates code for JSON content
|
|
159
|
+
*/
|
|
120
160
|
function generateJsonContentCode(postData) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
161
|
+
let prettyJson;
|
|
162
|
+
try {
|
|
163
|
+
prettyJson = JSON.stringify(JSON.parse(postData.text ?? '{}'), null, 2);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// If JSON parsing fails, use the raw text as-is
|
|
167
|
+
prettyJson = postData.text ?? '{}';
|
|
168
|
+
}
|
|
169
|
+
return `let content = new StringContent("""${prettyJson}""", Encoding.UTF8, "application/json")\n`;
|
|
129
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Generates code for application/x-www-form-urlencoded content
|
|
173
|
+
*/
|
|
130
174
|
function generateUrlEncodedFormDataCode(postData) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return code;
|
|
175
|
+
let code = 'let formUrlEncodedContentDictionary = new Dictionary<string, string>()\n';
|
|
176
|
+
for (const param of postData.params) {
|
|
177
|
+
code += `formUrlEncodedContentDictionary.Add("${escapeString(param.name ?? '')}", "${escapeString(param.value ?? '')}")\n`;
|
|
178
|
+
}
|
|
179
|
+
code += 'let content = new FormUrlEncodedContent(formUrlEncodedContentDictionary)\n';
|
|
180
|
+
return code;
|
|
138
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Escapes special characters for F# string literals
|
|
184
|
+
*/
|
|
139
185
|
function escapeString(str) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
186
|
+
if (str == null) {
|
|
187
|
+
return '';
|
|
188
|
+
}
|
|
189
|
+
return str
|
|
190
|
+
.replace(/\\/g, '\\\\') // Escape backslashes
|
|
191
|
+
.replace(/"/g, '\\"') // Escape double quotes
|
|
192
|
+
.replace(/\n/g, '\\n') // Escape newlines
|
|
193
|
+
.replace(/\r/g, '\\r') // Escape carriage returns
|
|
194
|
+
.replace(/\t/g, '\\t'); // Escape tabs
|
|
144
195
|
}
|
|
145
|
-
export {
|
|
146
|
-
fsharpHttpclient
|
|
147
|
-
};
|
|
148
|
-
//# sourceMappingURL=httpclient.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { native } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { native } from '../../../httpsnippet-lite/targets/go/native/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* go/native
|
|
5
|
+
*/
|
|
6
|
+
export const goNative = {
|
|
7
|
+
target: 'go',
|
|
8
|
+
client: 'native',
|
|
9
|
+
title: 'NewRequest',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(native, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
goNative
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http11.d.ts","sourceRoot":"","sources":["../../../../src/plugins/http/http11/http11.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpD;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"http11.d.ts","sourceRoot":"","sources":["../../../../src/plugins/http/http11/http11.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEpD;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,MAsHxB,CAAA"}
|
|
@@ -1,86 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Content-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
/**
|
|
2
|
+
* http/http1.1
|
|
3
|
+
*/
|
|
4
|
+
export const httpHttp11 = {
|
|
5
|
+
target: 'http',
|
|
6
|
+
client: 'http1.1',
|
|
7
|
+
title: 'HTTP/1.1',
|
|
8
|
+
generate(request) {
|
|
9
|
+
// Defaults
|
|
10
|
+
const normalizedRequest = {
|
|
11
|
+
method: 'GET',
|
|
12
|
+
headers: [],
|
|
13
|
+
queryString: [],
|
|
14
|
+
...request,
|
|
15
|
+
};
|
|
16
|
+
// Normalize method
|
|
17
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
18
|
+
// Parse URL with error handling
|
|
19
|
+
let url;
|
|
20
|
+
let path;
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(normalizedRequest.url || 'http://');
|
|
23
|
+
path = url.pathname + (url.search || '');
|
|
24
|
+
}
|
|
25
|
+
catch (_error) {
|
|
26
|
+
// Oops, got an invalid URL, use the provided URL directly.
|
|
27
|
+
path = normalizedRequest.url || '/';
|
|
28
|
+
}
|
|
29
|
+
const hostname = url?.hostname || 'UNKNOWN_HOSTNAME';
|
|
30
|
+
// Start building the request
|
|
31
|
+
let requestString = `${normalizedRequest.method} ${path} HTTP/1.1\r\n`;
|
|
32
|
+
// Handle query string parameters
|
|
33
|
+
if (normalizedRequest.queryString.length) {
|
|
34
|
+
const queryString = normalizedRequest.queryString
|
|
35
|
+
.map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`)
|
|
36
|
+
.join('&');
|
|
37
|
+
// Append query string to the path
|
|
38
|
+
requestString = `${normalizedRequest.method} ${path}?${queryString} HTTP/1.1\r\n`;
|
|
39
|
+
}
|
|
40
|
+
// Store all headers
|
|
41
|
+
const headers = new Map();
|
|
42
|
+
// Host header
|
|
43
|
+
headers.set('Host', hostname);
|
|
44
|
+
// Passed headers
|
|
45
|
+
normalizedRequest.headers.forEach((header) => {
|
|
46
|
+
if (headers.has(header.name)) {
|
|
47
|
+
headers.set(header.name, `${headers.get(header.name)}, ${header.value}`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
headers.set(header.name, header.value);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
// Query string parameters
|
|
54
|
+
if (normalizedRequest.queryString.length) {
|
|
55
|
+
const queryString = normalizedRequest.queryString
|
|
56
|
+
.map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value)}`)
|
|
57
|
+
.join('&');
|
|
58
|
+
// Append query string to the path
|
|
59
|
+
requestString = `${normalizedRequest.method} ${path}?${queryString} HTTP/1.1\r\n`;
|
|
60
|
+
}
|
|
61
|
+
// Request body
|
|
62
|
+
let body = '';
|
|
63
|
+
if (normalizedRequest.postData) {
|
|
64
|
+
// Always set the Content-Type header based on postData.mimeType
|
|
65
|
+
if (normalizedRequest.postData.mimeType === 'application/json' && normalizedRequest.postData.text) {
|
|
66
|
+
headers.set('Content-Type', 'application/json');
|
|
67
|
+
body = normalizedRequest.postData.text;
|
|
68
|
+
}
|
|
69
|
+
else if (normalizedRequest.postData.mimeType === 'application/octet-stream' &&
|
|
70
|
+
normalizedRequest.postData.text) {
|
|
71
|
+
headers.set('Content-Type', 'application/octet-stream');
|
|
72
|
+
body = normalizedRequest.postData.text;
|
|
73
|
+
}
|
|
74
|
+
else if (normalizedRequest.postData.mimeType === 'application/x-www-form-urlencoded' &&
|
|
75
|
+
normalizedRequest.postData.params) {
|
|
76
|
+
const formData = normalizedRequest.postData.params
|
|
77
|
+
.map((param) => `${encodeURIComponent(param.name)}=${encodeURIComponent(param.value ?? '')}`)
|
|
78
|
+
.join('&');
|
|
79
|
+
headers.set('Content-Type', 'application/x-www-form-urlencoded');
|
|
80
|
+
body = formData;
|
|
81
|
+
}
|
|
82
|
+
else if (normalizedRequest.postData.mimeType === 'multipart/form-data' && normalizedRequest.postData.params) {
|
|
83
|
+
const boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';
|
|
84
|
+
headers.set('Content-Type', `multipart/form-data; boundary=${boundary}`);
|
|
85
|
+
body =
|
|
86
|
+
normalizedRequest.postData.params
|
|
87
|
+
.map((param) => {
|
|
88
|
+
const contentTypeHeader = param.contentType ? `Content-Type: ${param.contentType}\r\n` : '';
|
|
89
|
+
if (param.fileName) {
|
|
90
|
+
return `--${boundary}\r\nContent-Disposition: form-data; name="${param.name}"; filename="${param.fileName}"\r\n${contentTypeHeader}\r\n`;
|
|
91
|
+
}
|
|
92
|
+
return `--${boundary}\r\nContent-Disposition: form-data; name="${param.name}"\r\n${contentTypeHeader}\r\n${param.value ?? ''}\r\n`;
|
|
93
|
+
})
|
|
94
|
+
.join('') + `--${boundary}--\r\n`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Add headers to requestString
|
|
98
|
+
headers.forEach((value, name) => {
|
|
99
|
+
requestString += `${name}: ${value}\r\n`;
|
|
100
|
+
});
|
|
101
|
+
// Add body to requestString
|
|
102
|
+
requestString += `\r\n${body}`;
|
|
103
|
+
return requestString;
|
|
104
|
+
},
|
|
82
105
|
};
|
|
83
|
-
export {
|
|
84
|
-
httpHttp11
|
|
85
|
-
};
|
|
86
|
-
//# sourceMappingURL=http11.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { asynchttp } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { asynchttp } from '../../../httpsnippet-lite/targets/java/asynchttp/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* java/asynchttp
|
|
5
|
+
*/
|
|
6
|
+
export const javaAsynchttp = {
|
|
7
|
+
target: 'java',
|
|
8
|
+
client: 'asynchttp',
|
|
9
|
+
title: 'AsyncHttp',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(asynchttp, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
javaAsynchttp
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=asynchttp.js.map
|