@readme/httpsnippet 3.1.3 → 4.0.2
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/README.md +63 -62
- package/dist/package.json +86 -0
- package/dist/src/fixtures/customTarget.js +15 -0
- package/dist/src/fixtures/mimetypes.js +77 -0
- package/dist/src/fixtures/requests/application-form-encoded.js +69 -0
- package/dist/src/fixtures/requests/application-json.js +72 -0
- package/dist/src/fixtures/requests/cookies.js +51 -0
- package/dist/src/fixtures/requests/custom-method.js +41 -0
- package/dist/src/fixtures/requests/full.js +99 -0
- package/dist/src/fixtures/requests/headers.js +56 -0
- package/dist/src/fixtures/requests/http-insecure.js +45 -0
- package/dist/src/fixtures/requests/jsonObj-multiline.js +59 -0
- package/dist/src/fixtures/requests/jsonObj-null-value.js +61 -0
- package/dist/src/fixtures/requests/multipart-data.js +72 -0
- package/dist/src/fixtures/requests/multipart-file.js +65 -0
- package/dist/src/fixtures/requests/multipart-form-data-no-params.js +56 -0
- package/dist/src/fixtures/requests/multipart-form-data.js +64 -0
- package/dist/src/fixtures/requests/nested.js +64 -0
- package/dist/src/fixtures/requests/query-encoded.js +59 -0
- package/dist/src/fixtures/requests/query.js +64 -0
- package/dist/src/fixtures/requests/short.js +45 -0
- package/dist/src/fixtures/requests/text-plain.js +57 -0
- package/dist/src/fixtures/runCustomFixtures.js +77 -0
- package/dist/src/helpers/code-builder.js +91 -0
- package/dist/src/helpers/form-data.js +157 -0
- package/dist/src/helpers/har-validator.js +76 -0
- package/dist/src/helpers/headers.js +33 -0
- package/dist/src/helpers/reducer.js +19 -0
- package/dist/src/helpers/shell.js +20 -0
- package/dist/src/helpers/utils.js +21 -0
- package/dist/src/index.js +285 -0
- package/dist/src/targets/c/libcurl/client.js +43 -0
- package/dist/src/targets/c/target.js +15 -0
- package/dist/src/targets/clojure/clj_http/client.js +184 -0
- package/dist/src/targets/clojure/target.js +15 -0
- package/dist/src/targets/csharp/httpclient/client.js +162 -0
- package/dist/src/targets/csharp/restsharp/client.js +38 -0
- package/dist/src/targets/csharp/target.js +17 -0
- package/dist/src/targets/go/native/client.js +122 -0
- package/dist/src/targets/go/target.js +15 -0
- package/dist/src/targets/http/http1.1/client.js +79 -0
- package/dist/src/targets/http/target.js +15 -0
- package/dist/src/targets/java/asynchttp/client.js +53 -0
- package/dist/src/targets/java/nethttp/client.js +52 -0
- package/dist/src/targets/java/okhttp/client.js +79 -0
- package/dist/src/targets/java/target.js +21 -0
- package/dist/src/targets/java/unirest/client.js +53 -0
- package/dist/src/targets/javascript/axios/client.js +101 -0
- package/dist/src/targets/javascript/axios/fixtures/application-form-encoded.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/application-json.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/cookies.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/custom-method.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/full.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/headers.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/http-insecure.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-multiline.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-null-value.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-data.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-file.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/nested.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/query-encoded.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/query.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/short.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/text-plain.js +19 -0
- package/dist/src/targets/javascript/fetch/client.js +115 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-form-encoded.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-json.js +16 -0
- package/dist/src/targets/javascript/fetch/fixtures/cookies.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/custom-method.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/full.js +13 -0
- package/dist/src/targets/javascript/fetch/fixtures/headers.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/http-insecure.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-multiline.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-null-value.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-data.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-file.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/nested.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query-encoded.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/short.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/text-plain.js +5 -0
- package/dist/src/targets/javascript/jquery/client.js +93 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-form-encoded.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-json.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/cookies.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/full.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/headers.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-data.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-file.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/text-plain.js +14 -0
- package/dist/src/targets/javascript/target.js +21 -0
- package/dist/src/targets/javascript/xhr/client.js +90 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-form-encoded.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-json.js +31 -0
- package/dist/src/targets/javascript/xhr/fixtures/cookies.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/cors.js +10 -0
- package/dist/src/targets/javascript/xhr/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/full.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/headers.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/text-plain.js +12 -0
- package/dist/src/targets/kotlin/okhttp/client.js +79 -0
- package/dist/src/targets/kotlin/target.js +15 -0
- package/dist/src/targets/node/axios/client.js +87 -0
- package/dist/src/targets/node/axios/fixtures/application-form-encoded.js +19 -0
- package/dist/src/targets/node/axios/fixtures/application-json.js +22 -0
- package/dist/src/targets/node/axios/fixtures/cookies.js +14 -0
- package/dist/src/targets/node/axios/fixtures/custom-method.js +10 -0
- package/dist/src/targets/node/axios/fixtures/full.js +22 -0
- package/dist/src/targets/node/axios/fixtures/headers.js +14 -0
- package/dist/src/targets/node/axios/fixtures/http-insecure.js +10 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-file.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data-no-params.js +14 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/nested.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query-encoded.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query.js +13 -0
- package/dist/src/targets/node/axios/fixtures/short.js +10 -0
- package/dist/src/targets/node/axios/fixtures/text-plain.js +15 -0
- package/dist/src/targets/node/fetch/client.js +149 -0
- package/dist/src/targets/node/fetch/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/fetch/fixtures/application-json.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/cookies.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/custom-method.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/full.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/headers.js +10 -0
- package/dist/src/targets/node/fetch/fixtures/http-insecure.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-multiline.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-null-value.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data-no-params.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/nested.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query-encoded.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/short.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/text-plain.js +7 -0
- package/dist/src/targets/node/native/client.js +91 -0
- package/dist/src/targets/node/native/fixtures/application-form-encoded.js +24 -0
- package/dist/src/targets/node/native/fixtures/application-json.js +30 -0
- package/dist/src/targets/node/native/fixtures/cookies.js +22 -0
- package/dist/src/targets/node/native/fixtures/custom-method.js +20 -0
- package/dist/src/targets/node/native/fixtures/full.js +26 -0
- package/dist/src/targets/node/native/fixtures/headers.js +24 -0
- package/dist/src/targets/node/native/fixtures/http-insecure.js +20 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-multiline.js +23 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-null-value.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-file.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data-no-params.js +22 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/nested.js +20 -0
- package/dist/src/targets/node/native/fixtures/query-encoded.js +20 -0
- package/dist/src/targets/node/native/fixtures/query.js +20 -0
- package/dist/src/targets/node/native/fixtures/short.js +20 -0
- package/dist/src/targets/node/native/fixtures/text-plain.js +23 -0
- package/dist/src/targets/node/request/client.js +116 -0
- package/dist/src/targets/node/request/fixtures/application-form-encoded.js +13 -0
- package/dist/src/targets/node/request/fixtures/application-json.js +21 -0
- package/dist/src/targets/node/request/fixtures/cookies.js +11 -0
- package/dist/src/targets/node/request/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/request/fixtures/full.js +20 -0
- package/dist/src/targets/node/request/fixtures/headers.js +12 -0
- package/dist/src/targets/node/request/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/node/request/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/request/fixtures/multipart-file.js +19 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data-no-params.js +12 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data.js +13 -0
- package/dist/src/targets/node/request/fixtures/nested.js +11 -0
- package/dist/src/targets/node/request/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/node/request/fixtures/query.js +11 -0
- package/dist/src/targets/node/request/fixtures/short.js +8 -0
- package/dist/src/targets/node/request/fixtures/text-plain.js +13 -0
- package/dist/src/targets/node/target.js +24 -0
- package/dist/src/targets/node/unirest/client.js +119 -0
- package/dist/src/targets/node/unirest/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/application-json.js +32 -0
- package/dist/src/targets/node/unirest/fixtures/cookies.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/full.js +27 -0
- package/dist/src/targets/node/unirest/fixtures/headers.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-file.js +18 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/nested.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/query-encoded.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/query.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/short.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/text-plain.js +12 -0
- package/dist/src/targets/objc/helpers.js +59 -0
- package/dist/src/targets/objc/nsurlsession/client.js +151 -0
- package/dist/src/targets/objc/target.js +15 -0
- package/dist/src/targets/ocaml/cohttp/client.js +72 -0
- package/dist/src/targets/ocaml/target.js +15 -0
- package/dist/src/targets/php/curl/client.js +135 -0
- package/dist/src/targets/php/guzzle/client.js +126 -0
- package/dist/src/targets/php/helpers.js +63 -0
- package/dist/src/targets/php/http1/client.js +90 -0
- package/dist/src/targets/php/http2/client.js +128 -0
- package/dist/src/targets/php/target.js +22 -0
- package/dist/src/targets/powershell/common.js +49 -0
- package/dist/src/targets/powershell/restmethod/client.js +13 -0
- package/dist/src/targets/powershell/target.js +17 -0
- package/dist/src/targets/powershell/webrequest/client.js +13 -0
- package/dist/src/targets/python/helpers.js +70 -0
- package/dist/src/targets/python/requests/client.js +161 -0
- package/dist/src/targets/python/target.js +16 -0
- package/dist/src/targets/r/httr/client.js +125 -0
- package/dist/src/targets/r/target.js +15 -0
- package/dist/src/targets/ruby/native/client.js +69 -0
- package/dist/src/targets/ruby/target.js +15 -0
- package/dist/src/targets/shell/curl/client.js +171 -0
- package/dist/src/targets/shell/httpie/client.js +111 -0
- package/dist/src/targets/shell/target.js +20 -0
- package/dist/src/targets/shell/wget/client.js +55 -0
- package/dist/src/targets/swift/helpers.js +80 -0
- package/dist/src/targets/swift/nsurlsession/client.js +156 -0
- package/dist/src/targets/swift/target.js +15 -0
- package/dist/src/targets/targets.js +130 -0
- package/package.json +26 -21
- package/src/helpers/code-builder.js +0 -108
- package/src/helpers/form-data.js +0 -107
- package/src/helpers/headers.js +0 -48
- package/src/helpers/reducer.js +0 -20
- package/src/index.js +0 -361
- package/src/targets/c/index.js +0 -10
- package/src/targets/c/libcurl.js +0 -45
- package/src/targets/clojure/clj_http.js +0 -176
- package/src/targets/clojure/index.js +0 -10
- package/src/targets/csharp/httpclient.js +0 -157
- package/src/targets/csharp/index.js +0 -11
- package/src/targets/csharp/restsharp.js +0 -49
- package/src/targets/go/index.js +0 -10
- package/src/targets/go/native.js +0 -130
- package/src/targets/http/http1.1.js +0 -89
- package/src/targets/http/index.js +0 -10
- package/src/targets/index.js +0 -20
- package/src/targets/java/asynchttp.js +0 -54
- package/src/targets/java/index.js +0 -13
- package/src/targets/java/nethttp.js +0 -59
- package/src/targets/java/okhttp.js +0 -78
- package/src/targets/java/unirest.js +0 -57
- package/src/targets/javascript/axios.js +0 -101
- package/src/targets/javascript/fetch.js +0 -129
- package/src/targets/javascript/index.js +0 -13
- package/src/targets/javascript/jquery.js +0 -89
- package/src/targets/javascript/xhr.js +0 -86
- package/src/targets/kotlin/index.js +0 -10
- package/src/targets/kotlin/okhttp.js +0 -78
- package/src/targets/node/axios.js +0 -76
- package/src/targets/node/fetch.js +0 -145
- package/src/targets/node/index.js +0 -15
- package/src/targets/node/native.js +0 -92
- package/src/targets/node/request.js +0 -126
- package/src/targets/node/unirest.js +0 -120
- package/src/targets/objc/helpers.js +0 -80
- package/src/targets/objc/index.js +0 -10
- package/src/targets/objc/nsurlsession.js +0 -164
- package/src/targets/ocaml/cohttp.js +0 -73
- package/src/targets/ocaml/index.js +0 -10
- package/src/targets/php/curl.js +0 -142
- package/src/targets/php/guzzle.js +0 -135
- package/src/targets/php/helpers.js +0 -87
- package/src/targets/php/http1.js +0 -85
- package/src/targets/php/http2.js +0 -131
- package/src/targets/php/index.js +0 -14
- package/src/targets/powershell/common.js +0 -60
- package/src/targets/powershell/index.js +0 -11
- package/src/targets/powershell/restmethod.js +0 -8
- package/src/targets/powershell/webrequest.js +0 -8
- package/src/targets/python/helpers.js +0 -85
- package/src/targets/python/index.js +0 -11
- package/src/targets/python/requests.js +0 -163
- package/src/targets/r/httr.js +0 -134
- package/src/targets/r/index.js +0 -10
- package/src/targets/ruby/index.js +0 -10
- package/src/targets/ruby/native.js +0 -71
- package/src/targets/shell/curl.js +0 -157
- package/src/targets/shell/helpers.js +0 -23
- package/src/targets/shell/httpie.js +0 -129
- package/src/targets/shell/index.js +0 -13
- package/src/targets/shell/wget.js +0 -52
- package/src/targets/swift/helpers.js +0 -93
- package/src/targets/swift/index.js +0 -10
- package/src/targets/swift/nsurlsession.js +0 -152
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
exports.__esModule = true;
|
|
14
|
+
exports.httpclient = void 0;
|
|
15
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
16
|
+
var headers_1 = require("../../../helpers/headers");
|
|
17
|
+
var getDecompressionMethods = function (allHeaders) {
|
|
18
|
+
var acceptEncodings = (0, headers_1.getHeader)(allHeaders, 'accept-encoding');
|
|
19
|
+
if (!acceptEncodings) {
|
|
20
|
+
return []; // no decompression
|
|
21
|
+
}
|
|
22
|
+
var supportedMethods = {
|
|
23
|
+
gzip: 'DecompressionMethods.GZip',
|
|
24
|
+
deflate: 'DecompressionMethods.Deflate'
|
|
25
|
+
};
|
|
26
|
+
var methods = [];
|
|
27
|
+
if (typeof acceptEncodings === 'string') {
|
|
28
|
+
acceptEncodings = [acceptEncodings];
|
|
29
|
+
}
|
|
30
|
+
acceptEncodings.forEach(function (acceptEncoding) {
|
|
31
|
+
acceptEncoding.split(',').forEach(function (encoding) {
|
|
32
|
+
var match = /\s*([^;\s]+)/.exec(encoding);
|
|
33
|
+
if (match) {
|
|
34
|
+
var method = supportedMethods[match[1]];
|
|
35
|
+
if (method) {
|
|
36
|
+
methods.push(method);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
return methods;
|
|
42
|
+
};
|
|
43
|
+
exports.httpclient = {
|
|
44
|
+
info: {
|
|
45
|
+
key: 'httpclient',
|
|
46
|
+
title: 'HttpClient',
|
|
47
|
+
link: 'https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient',
|
|
48
|
+
description: '.NET Standard HTTP Client'
|
|
49
|
+
},
|
|
50
|
+
convert: function (_a, options) {
|
|
51
|
+
var _b, _c;
|
|
52
|
+
var allHeaders = _a.allHeaders, postData = _a.postData, method = _a.method, fullUrl = _a.fullUrl;
|
|
53
|
+
var opts = __assign({ indent: ' ' }, options);
|
|
54
|
+
var _d = new code_builder_1.CodeBuilder({ indent: opts.indent }), push = _d.push, join = _d.join;
|
|
55
|
+
push('using System.Net.Http.Headers;');
|
|
56
|
+
var clienthandler = '';
|
|
57
|
+
var cookies = Boolean(allHeaders.cookie);
|
|
58
|
+
var decompressionMethods = getDecompressionMethods(allHeaders);
|
|
59
|
+
if (cookies || decompressionMethods.length) {
|
|
60
|
+
clienthandler = 'clientHandler';
|
|
61
|
+
push('var clientHandler = new HttpClientHandler');
|
|
62
|
+
push('{');
|
|
63
|
+
if (cookies) {
|
|
64
|
+
// enable setting the cookie header
|
|
65
|
+
push('UseCookies = false,', 1);
|
|
66
|
+
}
|
|
67
|
+
if (decompressionMethods.length) {
|
|
68
|
+
// enable decompression for supported methods
|
|
69
|
+
push("AutomaticDecompression = ".concat(decompressionMethods.join(' | '), ","), 1);
|
|
70
|
+
}
|
|
71
|
+
push('};');
|
|
72
|
+
}
|
|
73
|
+
push("var client = new HttpClient(".concat(clienthandler, ");"));
|
|
74
|
+
push('var request = new HttpRequestMessage');
|
|
75
|
+
push('{');
|
|
76
|
+
var methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'TRACE'];
|
|
77
|
+
method = method.toUpperCase();
|
|
78
|
+
if (method && methods.includes(method)) {
|
|
79
|
+
// buildin method
|
|
80
|
+
method = "HttpMethod.".concat(method[0]).concat(method.substring(1).toLowerCase());
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// custom method
|
|
84
|
+
method = "new HttpMethod(\"".concat(method, "\")");
|
|
85
|
+
}
|
|
86
|
+
push("Method = ".concat(method, ","), 1);
|
|
87
|
+
push("RequestUri = new Uri(\"".concat(fullUrl, "\"),"), 1);
|
|
88
|
+
var headers = Object.keys(allHeaders).filter(function (header) {
|
|
89
|
+
switch (header.toLowerCase()) {
|
|
90
|
+
case 'content-type':
|
|
91
|
+
case 'content-length':
|
|
92
|
+
case 'accept-encoding':
|
|
93
|
+
// skip these headers
|
|
94
|
+
return false;
|
|
95
|
+
default:
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
if (headers.length) {
|
|
100
|
+
push('Headers =', 1);
|
|
101
|
+
push('{', 1);
|
|
102
|
+
headers.forEach(function (key) {
|
|
103
|
+
push("{ \"".concat(String(key), "\", \"").concat(allHeaders[key], "\" },"), 2);
|
|
104
|
+
});
|
|
105
|
+
push('},', 1);
|
|
106
|
+
}
|
|
107
|
+
if (postData.text) {
|
|
108
|
+
var contentType = postData.mimeType;
|
|
109
|
+
switch (contentType) {
|
|
110
|
+
case 'application/x-www-form-urlencoded':
|
|
111
|
+
push('Content = new FormUrlEncodedContent(new Dictionary<string, string>', 1);
|
|
112
|
+
push('{', 1);
|
|
113
|
+
(_b = postData.params) === null || _b === void 0 ? void 0 : _b.forEach(function (param) {
|
|
114
|
+
push("{ \"".concat(param.name, "\", \"").concat(param.value, "\" },"), 2);
|
|
115
|
+
});
|
|
116
|
+
push('}),', 1);
|
|
117
|
+
break;
|
|
118
|
+
case 'multipart/form-data':
|
|
119
|
+
push('Content = new MultipartFormDataContent', 1);
|
|
120
|
+
push('{', 1);
|
|
121
|
+
(_c = postData.params) === null || _c === void 0 ? void 0 : _c.forEach(function (param) {
|
|
122
|
+
push("new StringContent(".concat(JSON.stringify(param.value || ''), ")"), 2);
|
|
123
|
+
push('{', 2);
|
|
124
|
+
push('Headers =', 3);
|
|
125
|
+
push('{', 3);
|
|
126
|
+
if (param.contentType) {
|
|
127
|
+
push("ContentType = new MediaTypeHeaderValue(\"".concat(param.contentType, "\"),"), 4);
|
|
128
|
+
}
|
|
129
|
+
push('ContentDisposition = new ContentDispositionHeaderValue("form-data")', 4);
|
|
130
|
+
push('{', 4);
|
|
131
|
+
push("Name = \"".concat(param.name, "\","), 5);
|
|
132
|
+
if (param.fileName) {
|
|
133
|
+
push("FileName = \"".concat(param.fileName, "\","), 5);
|
|
134
|
+
}
|
|
135
|
+
push('}', 4);
|
|
136
|
+
push('}', 3);
|
|
137
|
+
push('},', 2);
|
|
138
|
+
});
|
|
139
|
+
push('},', 1);
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
push("Content = new StringContent(".concat(JSON.stringify(postData.text || ''), ")"), 1);
|
|
143
|
+
push('{', 1);
|
|
144
|
+
push('Headers =', 2);
|
|
145
|
+
push('{', 2);
|
|
146
|
+
push("ContentType = new MediaTypeHeaderValue(\"".concat(contentType, "\")"), 3);
|
|
147
|
+
push('}', 2);
|
|
148
|
+
push('}', 1);
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
push('};');
|
|
153
|
+
// send and read response
|
|
154
|
+
push('using (var response = await client.SendAsync(request))');
|
|
155
|
+
push('{');
|
|
156
|
+
push('response.EnsureSuccessStatusCode();', 1);
|
|
157
|
+
push('var body = await response.Content.ReadAsStringAsync();', 1);
|
|
158
|
+
push('Console.WriteLine(body);', 1);
|
|
159
|
+
push('}');
|
|
160
|
+
return join();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.restsharp = void 0;
|
|
4
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
5
|
+
var headers_1 = require("../../../helpers/headers");
|
|
6
|
+
exports.restsharp = {
|
|
7
|
+
info: {
|
|
8
|
+
key: 'restsharp',
|
|
9
|
+
title: 'RestSharp',
|
|
10
|
+
link: 'http://restsharp.org/',
|
|
11
|
+
description: 'Simple REST and HTTP API Client for .NET'
|
|
12
|
+
},
|
|
13
|
+
convert: function (_a) {
|
|
14
|
+
var allHeaders = _a.allHeaders, method = _a.method, fullUrl = _a.fullUrl, headersObj = _a.headersObj, cookies = _a.cookies, postData = _a.postData;
|
|
15
|
+
var _b = new code_builder_1.CodeBuilder(), push = _b.push, join = _b.join;
|
|
16
|
+
var isSupportedMethod = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'].includes(method.toUpperCase());
|
|
17
|
+
if (!isSupportedMethod) {
|
|
18
|
+
return 'Method not supported';
|
|
19
|
+
}
|
|
20
|
+
push("var client = new RestClient(\"".concat(fullUrl, "\");"));
|
|
21
|
+
push("var request = new RestRequest(Method.".concat(method.toUpperCase(), ");"));
|
|
22
|
+
// Add headers, including the cookies
|
|
23
|
+
Object.keys(headersObj).forEach(function (key) {
|
|
24
|
+
push("request.AddHeader(\"".concat(key, "\", \"").concat(headersObj[key], "\");"));
|
|
25
|
+
});
|
|
26
|
+
cookies.forEach(function (_a) {
|
|
27
|
+
var name = _a.name, value = _a.value;
|
|
28
|
+
push("request.AddCookie(\"".concat(name, "\", \"").concat(value, "\");"));
|
|
29
|
+
});
|
|
30
|
+
if (postData.text) {
|
|
31
|
+
var header = (0, headers_1.getHeader)(allHeaders, 'content-type');
|
|
32
|
+
var text = JSON.stringify(postData.text);
|
|
33
|
+
push("request.AddParameter(\"".concat(header, "\", ").concat(text, ", ParameterType.RequestBody);"));
|
|
34
|
+
}
|
|
35
|
+
push('IRestResponse response = client.Execute(request);');
|
|
36
|
+
return join();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.csharp = void 0;
|
|
4
|
+
var client_1 = require("./httpclient/client");
|
|
5
|
+
var client_2 = require("./restsharp/client");
|
|
6
|
+
exports.csharp = {
|
|
7
|
+
info: {
|
|
8
|
+
key: 'csharp',
|
|
9
|
+
title: 'C#',
|
|
10
|
+
extname: '.cs',
|
|
11
|
+
"default": 'restsharp'
|
|
12
|
+
},
|
|
13
|
+
clientsById: {
|
|
14
|
+
httpclient: client_1.httpclient,
|
|
15
|
+
restsharp: client_2.restsharp
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* HTTP code snippet generator for native Go.
|
|
5
|
+
*
|
|
6
|
+
* @author
|
|
7
|
+
* @montanaflynn
|
|
8
|
+
*
|
|
9
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
10
|
+
*/
|
|
11
|
+
var __assign = (this && this.__assign) || function () {
|
|
12
|
+
__assign = Object.assign || function(t) {
|
|
13
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
14
|
+
s = arguments[i];
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
};
|
|
20
|
+
return __assign.apply(this, arguments);
|
|
21
|
+
};
|
|
22
|
+
exports.__esModule = true;
|
|
23
|
+
exports.native = void 0;
|
|
24
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
25
|
+
exports.native = {
|
|
26
|
+
info: {
|
|
27
|
+
key: 'native',
|
|
28
|
+
title: 'NewRequest',
|
|
29
|
+
link: 'http://golang.org/pkg/net/http/#NewRequest',
|
|
30
|
+
description: 'Golang HTTP client request'
|
|
31
|
+
},
|
|
32
|
+
convert: function (_a, options) {
|
|
33
|
+
var postData = _a.postData, method = _a.method, allHeaders = _a.allHeaders, fullUrl = _a.fullUrl;
|
|
34
|
+
var _b = new code_builder_1.CodeBuilder({ indent: '\t' }), blank = _b.blank, push = _b.push, join = _b.join;
|
|
35
|
+
var opts = __assign({ showBoilerplate: true, checkErrors: false, printBody: true, timeout: -1 }, options);
|
|
36
|
+
var errorPlaceholder = opts.checkErrors ? 'err' : '_';
|
|
37
|
+
var indent = opts.showBoilerplate ? 1 : 0;
|
|
38
|
+
var errorCheck = function () {
|
|
39
|
+
if (opts.checkErrors) {
|
|
40
|
+
push('if err != nil {', indent);
|
|
41
|
+
push('panic(err)', indent + 1);
|
|
42
|
+
push('}', indent);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
// Create boilerplate
|
|
46
|
+
if (opts.showBoilerplate) {
|
|
47
|
+
push('package main');
|
|
48
|
+
blank();
|
|
49
|
+
push('import (');
|
|
50
|
+
push('"fmt"', indent);
|
|
51
|
+
if (opts.timeout > 0) {
|
|
52
|
+
push('"time"', indent);
|
|
53
|
+
}
|
|
54
|
+
if (postData.text) {
|
|
55
|
+
push('"strings"', indent);
|
|
56
|
+
}
|
|
57
|
+
push('"net/http"', indent);
|
|
58
|
+
if (opts.printBody) {
|
|
59
|
+
push('"io/ioutil"', indent);
|
|
60
|
+
}
|
|
61
|
+
push(')');
|
|
62
|
+
blank();
|
|
63
|
+
push('func main() {');
|
|
64
|
+
blank();
|
|
65
|
+
}
|
|
66
|
+
// Create client
|
|
67
|
+
var client;
|
|
68
|
+
if (opts.timeout > 0) {
|
|
69
|
+
client = 'client';
|
|
70
|
+
push('client := http.Client{', indent);
|
|
71
|
+
push("Timeout: time.Duration(".concat(opts.timeout, " * time.Second),"), indent + 1);
|
|
72
|
+
push('}', indent);
|
|
73
|
+
blank();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
client = 'http.DefaultClient';
|
|
77
|
+
}
|
|
78
|
+
push("url := \"".concat(fullUrl, "\""), indent);
|
|
79
|
+
blank();
|
|
80
|
+
// If we have body content or not create the var and reader or nil
|
|
81
|
+
if (postData.text) {
|
|
82
|
+
push("payload := strings.NewReader(".concat(JSON.stringify(postData.text), ")"), indent);
|
|
83
|
+
blank();
|
|
84
|
+
push("req, ".concat(errorPlaceholder, " := http.NewRequest(\"").concat(method, "\", url, payload)"), indent);
|
|
85
|
+
blank();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
push("req, ".concat(errorPlaceholder, " := http.NewRequest(\"").concat(method, "\", url, nil)"), indent);
|
|
89
|
+
blank();
|
|
90
|
+
}
|
|
91
|
+
errorCheck();
|
|
92
|
+
// Add headers
|
|
93
|
+
if (Object.keys(allHeaders).length) {
|
|
94
|
+
Object.keys(allHeaders).forEach(function (key) {
|
|
95
|
+
push("req.Header.Add(\"".concat(key, "\", \"").concat(allHeaders[key], "\")"), indent);
|
|
96
|
+
});
|
|
97
|
+
blank();
|
|
98
|
+
}
|
|
99
|
+
// Make request
|
|
100
|
+
push("res, ".concat(errorPlaceholder, " := ").concat(client, ".Do(req)"), indent);
|
|
101
|
+
errorCheck();
|
|
102
|
+
// Get Body
|
|
103
|
+
if (opts.printBody) {
|
|
104
|
+
blank();
|
|
105
|
+
push('defer res.Body.Close()', indent);
|
|
106
|
+
push("body, ".concat(errorPlaceholder, " := ioutil.ReadAll(res.Body)"), indent);
|
|
107
|
+
errorCheck();
|
|
108
|
+
}
|
|
109
|
+
// Print it
|
|
110
|
+
blank();
|
|
111
|
+
push('fmt.Println(res)', indent);
|
|
112
|
+
if (opts.printBody) {
|
|
113
|
+
push('fmt.Println(string(body))', indent);
|
|
114
|
+
}
|
|
115
|
+
// End main block
|
|
116
|
+
if (opts.showBoilerplate) {
|
|
117
|
+
blank();
|
|
118
|
+
push('}');
|
|
119
|
+
}
|
|
120
|
+
return join();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.go = void 0;
|
|
4
|
+
var client_1 = require("./native/client");
|
|
5
|
+
exports.go = {
|
|
6
|
+
info: {
|
|
7
|
+
key: 'go',
|
|
8
|
+
title: 'Go',
|
|
9
|
+
extname: '.go',
|
|
10
|
+
"default": 'native'
|
|
11
|
+
},
|
|
12
|
+
clientsById: {
|
|
13
|
+
native: client_1.native
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* HTTP code snippet generator to generate raw HTTP/1.1 request strings,
|
|
5
|
+
* in accordance to the RFC 7230 (and RFC 7231) specifications.
|
|
6
|
+
*
|
|
7
|
+
* @author
|
|
8
|
+
* @irvinlim
|
|
9
|
+
*
|
|
10
|
+
* For any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
11
|
+
*/
|
|
12
|
+
var __assign = (this && this.__assign) || function () {
|
|
13
|
+
__assign = Object.assign || function(t) {
|
|
14
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
15
|
+
s = arguments[i];
|
|
16
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
17
|
+
t[p] = s[p];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
return __assign.apply(this, arguments);
|
|
22
|
+
};
|
|
23
|
+
exports.__esModule = true;
|
|
24
|
+
exports.http11 = void 0;
|
|
25
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
26
|
+
var CRLF = '\r\n';
|
|
27
|
+
/**
|
|
28
|
+
* Request follows the request message format in accordance to RFC 7230, Section 3.
|
|
29
|
+
* Each section is prepended with the RFC and section number.
|
|
30
|
+
* See more at https://tools.ietf.org/html/rfc7230#section-3.
|
|
31
|
+
*/
|
|
32
|
+
exports.http11 = {
|
|
33
|
+
info: {
|
|
34
|
+
key: 'http1.1',
|
|
35
|
+
title: 'HTTP/1.1',
|
|
36
|
+
link: 'https://tools.ietf.org/html/rfc7230',
|
|
37
|
+
description: 'HTTP/1.1 request string in accordance with RFC 7230'
|
|
38
|
+
},
|
|
39
|
+
convert: function (_a, options) {
|
|
40
|
+
var method = _a.method, fullUrl = _a.fullUrl, uriObj = _a.uriObj, httpVersion = _a.httpVersion, allHeaders = _a.allHeaders, postData = _a.postData;
|
|
41
|
+
var opts = __assign({ absoluteURI: false, autoContentLength: true, autoHost: true }, options);
|
|
42
|
+
// RFC 7230 Section 3. Message Format
|
|
43
|
+
// All lines have no indentation, and should be terminated with CRLF.
|
|
44
|
+
var _b = new code_builder_1.CodeBuilder({ indent: '', join: CRLF }), blank = _b.blank, push = _b.push, join = _b.join;
|
|
45
|
+
// RFC 7230 Section 5.3. Request Target
|
|
46
|
+
// Determines if the Request-Line should use 'absolute-form' or 'origin-form'.
|
|
47
|
+
// Basically it means whether the "http://domain.com" will prepend the full url.
|
|
48
|
+
var requestUrl = opts.absoluteURI ? fullUrl : uriObj.path;
|
|
49
|
+
// RFC 7230 Section 3.1.1. Request-Line
|
|
50
|
+
push("".concat(method, " ").concat(requestUrl, " ").concat(httpVersion));
|
|
51
|
+
var headerKeys = Object.keys(allHeaders);
|
|
52
|
+
// RFC 7231 Section 5. Header Fields
|
|
53
|
+
headerKeys.forEach(function (key) {
|
|
54
|
+
// Capitalize header keys, even though it's not required by the spec.
|
|
55
|
+
var keyCapitalized = key.toLowerCase().replace(/(^|-)(\w)/g, function (input) { return input.toUpperCase(); });
|
|
56
|
+
push("".concat(keyCapitalized, ": ").concat(allHeaders[key]));
|
|
57
|
+
});
|
|
58
|
+
// RFC 7230 Section 5.4. Host
|
|
59
|
+
// Automatically set Host header if option is on and on header already exists.
|
|
60
|
+
if (opts.autoHost && !headerKeys.includes('host')) {
|
|
61
|
+
push("Host: ".concat(uriObj.host));
|
|
62
|
+
}
|
|
63
|
+
// RFC 7230 Section 3.3.3. Message Body Length
|
|
64
|
+
// Automatically set Content-Length header if option is on, postData is present and no header already exists.
|
|
65
|
+
if (opts.autoContentLength && postData.text && !headerKeys.includes('content-length')) {
|
|
66
|
+
var length = Buffer.byteLength(postData.text, 'ascii').toString();
|
|
67
|
+
push("Content-Length: ".concat(length));
|
|
68
|
+
}
|
|
69
|
+
// Add extra line after header section.
|
|
70
|
+
blank();
|
|
71
|
+
// Separate header section and message body section.
|
|
72
|
+
var headerSection = join();
|
|
73
|
+
// RFC 7230 Section 3.3. Message Body
|
|
74
|
+
var messageBody = postData.text || '';
|
|
75
|
+
// RFC 7230 Section 3. Message Format
|
|
76
|
+
// Extra CRLF separating the headers from the body.
|
|
77
|
+
return "".concat(headerSection).concat(CRLF).concat(messageBody);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.http = void 0;
|
|
4
|
+
var client_1 = require("./http1.1/client");
|
|
5
|
+
exports.http = {
|
|
6
|
+
info: {
|
|
7
|
+
key: 'http',
|
|
8
|
+
title: 'HTTP',
|
|
9
|
+
extname: null,
|
|
10
|
+
"default": '1.1'
|
|
11
|
+
},
|
|
12
|
+
clientsById: {
|
|
13
|
+
'http1.1': client_1.http11
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* Asynchronous Http and WebSocket Client library for Java
|
|
5
|
+
*
|
|
6
|
+
* @author
|
|
7
|
+
* @windard
|
|
8
|
+
*
|
|
9
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
10
|
+
*/
|
|
11
|
+
var __assign = (this && this.__assign) || function () {
|
|
12
|
+
__assign = Object.assign || function(t) {
|
|
13
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
14
|
+
s = arguments[i];
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
};
|
|
20
|
+
return __assign.apply(this, arguments);
|
|
21
|
+
};
|
|
22
|
+
exports.__esModule = true;
|
|
23
|
+
exports.asynchttp = void 0;
|
|
24
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
25
|
+
exports.asynchttp = {
|
|
26
|
+
info: {
|
|
27
|
+
key: 'asynchttp',
|
|
28
|
+
title: 'AsyncHttp',
|
|
29
|
+
link: 'https://github.com/AsyncHttpClient/async-http-client',
|
|
30
|
+
description: 'Asynchronous Http and WebSocket Client library for Java'
|
|
31
|
+
},
|
|
32
|
+
convert: function (_a, options) {
|
|
33
|
+
var method = _a.method, allHeaders = _a.allHeaders, postData = _a.postData, fullUrl = _a.fullUrl;
|
|
34
|
+
var opts = __assign({ indent: ' ' }, options);
|
|
35
|
+
var _b = new code_builder_1.CodeBuilder({ indent: opts.indent }), blank = _b.blank, push = _b.push, join = _b.join;
|
|
36
|
+
push('AsyncHttpClient client = new DefaultAsyncHttpClient();');
|
|
37
|
+
push("client.prepare(\"".concat(method.toUpperCase(), "\", \"").concat(fullUrl, "\")"));
|
|
38
|
+
// Add headers, including the cookies
|
|
39
|
+
Object.keys(allHeaders).forEach(function (key) {
|
|
40
|
+
push(".setHeader(\"".concat(key, "\", \"").concat(allHeaders[key], "\")"), 1);
|
|
41
|
+
});
|
|
42
|
+
if (postData.text) {
|
|
43
|
+
push(".setBody(".concat(JSON.stringify(postData.text), ")"), 1);
|
|
44
|
+
}
|
|
45
|
+
push('.execute()', 1);
|
|
46
|
+
push('.toCompletableFuture()', 1);
|
|
47
|
+
push('.thenAccept(System.out::println)', 1);
|
|
48
|
+
push('.join();', 1);
|
|
49
|
+
blank();
|
|
50
|
+
push('client.close();');
|
|
51
|
+
return join();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* HTTP code snippet generator for Java using java.net.http.
|
|
5
|
+
*
|
|
6
|
+
* @author
|
|
7
|
+
* @wtetsu
|
|
8
|
+
*
|
|
9
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
10
|
+
*/
|
|
11
|
+
var __assign = (this && this.__assign) || function () {
|
|
12
|
+
__assign = Object.assign || function(t) {
|
|
13
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
14
|
+
s = arguments[i];
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
};
|
|
20
|
+
return __assign.apply(this, arguments);
|
|
21
|
+
};
|
|
22
|
+
exports.__esModule = true;
|
|
23
|
+
exports.nethttp = void 0;
|
|
24
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
25
|
+
exports.nethttp = {
|
|
26
|
+
info: {
|
|
27
|
+
key: 'nethttp',
|
|
28
|
+
title: 'java.net.http',
|
|
29
|
+
link: 'https://openjdk.java.net/groups/net/httpclient/intro.html',
|
|
30
|
+
description: 'Java Standardized HTTP Client API'
|
|
31
|
+
},
|
|
32
|
+
convert: function (_a, options) {
|
|
33
|
+
var allHeaders = _a.allHeaders, fullUrl = _a.fullUrl, method = _a.method, postData = _a.postData;
|
|
34
|
+
var opts = __assign({ indent: ' ' }, options);
|
|
35
|
+
var _b = new code_builder_1.CodeBuilder({ indent: opts.indent }), push = _b.push, join = _b.join;
|
|
36
|
+
push('HttpRequest request = HttpRequest.newBuilder()');
|
|
37
|
+
push(".uri(URI.create(\"".concat(fullUrl, "\"))"), 2);
|
|
38
|
+
Object.keys(allHeaders).forEach(function (key) {
|
|
39
|
+
push(".header(\"".concat(key, "\", \"").concat(allHeaders[key], "\")"), 2);
|
|
40
|
+
});
|
|
41
|
+
if (postData.text) {
|
|
42
|
+
push(".method(\"".concat(method.toUpperCase(), "\", HttpRequest.BodyPublishers.ofString(").concat(JSON.stringify(postData.text), "))"), 2);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
push(".method(\"".concat(method.toUpperCase(), "\", HttpRequest.BodyPublishers.noBody())"), 2);
|
|
46
|
+
}
|
|
47
|
+
push('.build();', 2);
|
|
48
|
+
push('HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());');
|
|
49
|
+
push('System.out.println(response.body());');
|
|
50
|
+
return join();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @description
|
|
4
|
+
* HTTP code snippet generator for Java using OkHttp.
|
|
5
|
+
*
|
|
6
|
+
* @author
|
|
7
|
+
* @shashiranjan84
|
|
8
|
+
*
|
|
9
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
10
|
+
*/
|
|
11
|
+
var __assign = (this && this.__assign) || function () {
|
|
12
|
+
__assign = Object.assign || function(t) {
|
|
13
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
14
|
+
s = arguments[i];
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
}
|
|
18
|
+
return t;
|
|
19
|
+
};
|
|
20
|
+
return __assign.apply(this, arguments);
|
|
21
|
+
};
|
|
22
|
+
exports.__esModule = true;
|
|
23
|
+
exports.okhttp = void 0;
|
|
24
|
+
var code_builder_1 = require("../../../helpers/code-builder");
|
|
25
|
+
exports.okhttp = {
|
|
26
|
+
info: {
|
|
27
|
+
key: 'okhttp',
|
|
28
|
+
title: 'OkHttp',
|
|
29
|
+
link: 'http://square.github.io/okhttp/',
|
|
30
|
+
description: 'An HTTP Request Client Library'
|
|
31
|
+
},
|
|
32
|
+
convert: function (_a, options) {
|
|
33
|
+
var postData = _a.postData, method = _a.method, fullUrl = _a.fullUrl, allHeaders = _a.allHeaders;
|
|
34
|
+
var opts = __assign({ indent: ' ' }, options);
|
|
35
|
+
var _b = new code_builder_1.CodeBuilder({ indent: opts.indent }), push = _b.push, blank = _b.blank, join = _b.join;
|
|
36
|
+
var methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'];
|
|
37
|
+
var methodsWithBody = ['POST', 'PUT', 'DELETE', 'PATCH'];
|
|
38
|
+
push('OkHttpClient client = new OkHttpClient();');
|
|
39
|
+
blank();
|
|
40
|
+
if (postData.text) {
|
|
41
|
+
if (postData.boundary) {
|
|
42
|
+
push("MediaType mediaType = MediaType.parse(\"".concat(postData.mimeType, "; boundary=").concat(postData.boundary, "\");"));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
push("MediaType mediaType = MediaType.parse(\"".concat(postData.mimeType, "\");"));
|
|
46
|
+
}
|
|
47
|
+
push("RequestBody body = RequestBody.create(mediaType, ".concat(JSON.stringify(postData.text), ");"));
|
|
48
|
+
}
|
|
49
|
+
push('Request request = new Request.Builder()');
|
|
50
|
+
push(".url(\"".concat(fullUrl, "\")"), 1);
|
|
51
|
+
if (!methods.includes(method.toUpperCase())) {
|
|
52
|
+
if (postData.text) {
|
|
53
|
+
push(".method(\"".concat(method.toUpperCase(), "\", body)"), 1);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
push(".method(\"".concat(method.toUpperCase(), "\", null)"), 1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (methodsWithBody.includes(method.toUpperCase())) {
|
|
60
|
+
if (postData.text) {
|
|
61
|
+
push(".".concat(method.toLowerCase(), "(body)"), 1);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
push(".".concat(method.toLowerCase(), "(null)"), 1);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
push(".".concat(method.toLowerCase(), "()"), 1);
|
|
69
|
+
}
|
|
70
|
+
// Add headers, including the cookies
|
|
71
|
+
Object.keys(allHeaders).forEach(function (key) {
|
|
72
|
+
push(".addHeader(\"".concat(key, "\", \"").concat(allHeaders[key], "\")"), 1);
|
|
73
|
+
});
|
|
74
|
+
push('.build();', 1);
|
|
75
|
+
blank();
|
|
76
|
+
push('Response response = client.newCall(request).execute();');
|
|
77
|
+
return join();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.java = void 0;
|
|
4
|
+
var client_1 = require("./asynchttp/client");
|
|
5
|
+
var client_2 = require("./nethttp/client");
|
|
6
|
+
var client_3 = require("./okhttp/client");
|
|
7
|
+
var client_4 = require("./unirest/client");
|
|
8
|
+
exports.java = {
|
|
9
|
+
info: {
|
|
10
|
+
key: 'java',
|
|
11
|
+
title: 'Java',
|
|
12
|
+
extname: '.java',
|
|
13
|
+
"default": 'unirest'
|
|
14
|
+
},
|
|
15
|
+
clientsById: {
|
|
16
|
+
asynchttp: client_1.asynchttp,
|
|
17
|
+
nethttp: client_2.nethttp,
|
|
18
|
+
okhttp: client_3.okhttp,
|
|
19
|
+
unirest: client_4.unirest
|
|
20
|
+
}
|
|
21
|
+
};
|